如何保护webHttpBinding?

Jai*_*hai 9 ssl wcf json web-config

在我的WCF服务中,我试图通过SSL连接使用JSON将数据发送到客户端.我能够使用wsHttpBinding安全模式将OData数据库源保护到我的客户端Transport.为什么webHttpBinding不能这样做才能使用SSL?如何配置需要使用JSON以使用SSL连接的端点?

基本上webHttpBindingwsHttpBinding?之间有什么区别?

<bindings>
  <wsHttpBinding>
    <binding name="TransportSecurity">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="EndpBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="ServiceBehavior" name="DataService4.DataService">

    <endpoint address="" binding="webHttpBinding" contract="DataService4.IService" bindingConfiguration="TransportSecurity" behaviorConfiguration="EndpBehavior" />

    <endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex" />   
  </service>
</services>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
Run Code Online (Sandbox Code Playgroud)

小智 12

我认为这篇文章将解决您的问题. 创建WCF RESTful服务并使用HTTPS over SSL保护它

  • 链接已损坏。这就是为什么仅链接答案不应被视为答案的原因。 (2认同)

小智 11

来自http://www.allenconway.net/2012/05/creating-wcf-restful-service-and-secure.html的相关部分是这样的:

<bindings>
  <webHttpBinding>
    <binding>
      <security mode="Transport" />
    </binding>
  </webHttpBinding>
</bindings> 
Run Code Online (Sandbox Code Playgroud)

但如果需要,还可以删除公开元数据.

详情请见msdn:https://msdn.microsoft.com/en-us/library/bb924478(v = vs1010).aspx

相关部分是:

使用HTTPS提供传输安全性.该服务需要使用SSL证书进行配置.使用HTTPS完全保护消息,并且客户端使用服务的SSL证书对服务进行身份验证.客户端身份验证通过webHttpBinding传输的ClientCredentialType属性进行控制.