我正在使用C#和.NET Framework 4.0开发WCF服务。

我正在使用webHttpBinding来做到这一点:

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "filteredOrders/")]
OrderContract[] GetOrders(IdsMessage msg);

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "completeFilteredOrders/")]
OrderContract[] LoadCompleteFilteredOrders(IdsMessage msg);

但是现在我需要使用流将图像发送到该Web服务,并且需要添加basicHttpBinding来完成此操作。

如何为使用[OperationContract]的WCF Web服务添加一个新的basicHttpBinding

抱歉,我对WCF开发很陌生。

顺便说一句,这是我的 Web.config :

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="EReportService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="EReportService.IRestServiceImpl" behaviorConfiguration="web">
        </endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding maxReceivedMessageSize="2097152" maxBufferSize="2097152" transferMode="Streamed"/>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <connectionStrings>

  </connectionStrings>
</configuration>

最佳答案

只需使用不同的地址创建另一个端点(两个端点不能共享相同的地址)-您可以修改现有的OperationContract来创建非RESTful方法。

 <system.serviceModel>
    <services>
      <service name="EReportService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="EReportService.IRestServiceImpl" behaviorConfiguration="web">
        </endpoint>
        <endpoint address="soap" binding="basicHttpBinding" contract="EReportService.IRestServiceImpl" >
        </endpoint>
      </service>
    </services>
 </system.serviceModel>

关于c# - basicHttpBinding和webHttpBinding在一起,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13611928/

10-10 22:55