基本的HTTP绑定和Web HTTP绑定一起使用

6

我正在使用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来实现。

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

很抱歉,我对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>

1
一个可能的解决方案:http://debugmode.net/2011/12/22/how-to-enable-rest-and-soap-both-on-the-same-wcf-service/ - VansFannel
1个回答

9

只需创建另一个使用不同地址的端点(两个端点不能共享相同的地址)- 您可以修改现有的 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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接