basicHttpBinding& webHttpBinding在一起

时间:2012-11-28 18:26:25

标签: c# wcf rest soap wcf-binding

我正在使用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>

1 个答案:

答案 0 :(得分:8)

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