0

请不要将其标记为重复。我已经多次尝试但失败了。

我正在获取流内容并使用静态名称保存我的图像。但我无法将图像文件名、扩展名参数发送到该帖子 URL。

我的代码如下

我的网络配置

<?xml version="1.0" encoding="UTF-8"?>

<system.web>
    <compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
    <services>
        <service name="PracticeWcfService1.Service1" behaviorConfiguration="ServiceBehaviour">

            <endpoint name="RestClient"
                      address="RestType"
                      binding="webHttpBinding"
                      contract="PracticeWcfService1.IService1"
                      behaviorConfiguration="PracticeWcfService1.Service1ehaviour" >
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint name="RestClientWithSecure"
                      address="RestTypeWithSecure"
                      binding="webHttpBinding"
                      contract="PracticeWcfService1.IService1"
                      bindingConfiguration="PracticeWcfService1.Services.ClientServicesEndpointBinding"
                      behaviorConfiguration="PracticeWcfService1.Service1ehaviour" >
                <!--bindingConfiguration used to give the security mode like HTTPS-->
                <!--behaviorConfiguration used to define type of endpointBehaviors-->
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint  name="SoapClient"
                address="SoapType"
                binding="basicHttpBinding"
                contract="PracticeWcfService1.IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>

            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>

            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:33333/Service1.svc" />
                </baseAddresses>
            </host>

        </service>
    </services>
    <bindings>
        <webHttpBinding>
            <binding name="PracticeWcfService1.Services.ClientServicesEndpointBinding" transferMode="Streamed" maxBufferSize="2147483647"
                     maxReceivedMessageSize="2147483647" openTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:10:00">
                <security mode="Transport">
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
    <behaviors>
        <endpointBehaviors>
            <behavior name="PracticeWcfService1.Service1ehaviour">
                <webHttp/> <!--helpEnabled="true" automaticFormatSelectionEnabled="true"-->
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehaviour">
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceThrottling maxConcurrentCalls="500" maxConcurrentInstances="250"/>
            </behavior>

        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
</system.webServer>

在 IService1 接口中:

[OperationContract]
        string RecieveImage(string fileName, Stream ImageStream);

在 Service1.svc.cs

    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "UploadFile/{fileName}")] 
            public string RecieveImage(string fileName, Stream ImageStream)
                using (FileStream fs = new FileStream(@"\\192.168.1.2\Common\Pratap\" + fileName + ".jpeg", FileMode.Create))
                {
                    ImageStream.CopyTo(fs);
                    ImageStream.Close();
                }
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.BadRequest);
            }
            return "Successsfully recieved.";

在服务视图标记中:

<%@ ServiceHost Language="C#" Debug="true" Service="PracticeWcfService1.Service1" CodeBehind="Service1.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory"%>

请清除我的问题...

4

0 回答 0