是的,正如您在两天前为我们的一些服务所做的配置中提到的那样,有一个更好的解决方案。
如下添加basicHttpBinding:
<basicHttpBinding>
<binding allowCookies="true" openTimeout="00:00:10" maxReceivedMessageSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000" />
<security mode="None" />
</binding>
<binding name="secureBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
和服务端点:
<service name="ServiceName">
<endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureBasicHttpBinding" contract="your service contract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/Service.svc"/>
</baseAddresses>
</host>
</service>
在 IIS 中您只需要添加有效证书并启用它,https 使用 secureBasicHttpBinding 和 http 使用默认基本 httpConfiguration。
我之前已经测试过它,现在一些客户在 https 中使用该服务,而其他一些客户正在使用 http。
提示:
在本地模式下,通过上述配置托管WCF 服务时出现错误,所以我得出这个结论,将该配置置于release 模式而不是debug 模式,因为https 在工作服务器上启用.
所以在release 配置中有类似的东西(发布后转移):
<service name="ServiceName" xdt:Locator="Match(name)" xdt:Transform="Replace">
<endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" contract="System.Data.Services.IRequestHandler">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="rest" behaviorConfiguration="Rest.Behavior" binding="webHttpBinding" bindingConfiguration="secureBasicHttpBinding" contract="your service contract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/AAA/Service.svc"/>
</baseAddresses>
</host>
</service>