我有一个使用basicHttpBinding的WCF服务。这作为HTTP公开给许多客户端。
现在,我们的要求是向少数新客户端公开此服务作为HTTPS,而我们不应破坏通过http进行消费的现有客户端。
我遇到了以编程方式检测安全类型,然后公开的方法,但是还有其他更好,更简便的方法吗?仅使用端点配置等?
我在这些领域还很陌生,请提供示例帮助
答案 0 :(得分:0)
是的,有一个更好的解决方案,正如您提到的,我两天前就为我们的某些服务进行了配置。
添加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
模式,因为{{ 1}}在工作服务器上启用。
因此在https
的配置中有类似的东西(发布后将被传输):
release