在 IIS 中发布 WCF 服务,同时支持 HTTP 和 HTTPS
我有一个使用 webHttpBinding 配置了两个端点的 WCF 服务,一个用于 http,另一个用于 https。它们使用相同的地址,端点只是使用的协议不同:
<服务名称=“Blubb.ClientService”>
<端点绑定=“webHttpBinding”绑定配置=“webBindingConfig”behaviorConfiguration=“webBehaviour” 合同=“Blubb.Contracts.IClientService”/>
<端点绑定=“webHttpBinding”绑定配置=“sslWebBindingConfig”行为配置=“webBehaviour” 合同=“Blubb.Contracts.IClientService”/>
<服务>
使用以下行为和绑定:
<行为>
<端点行为>
<行为名称=“webBehaviour”>
<绑定>
<绑定名称=“webBindingConfig”>
<安全模式=“无”/>
<绑定名称=“sslWebBindingConfig”>
<安全模式=“传输”/>
。
当我在 IIS 6 上安装证书时,两个端点都可以正常工作
如果未安装证书,HTTPS 端点肯定无法工作。但 HTTP 端点也不起作用。它失败并出现令人恼火的异常:当我使用 http://localhost:8080/ClientManagement/ 访问服务时ClientService.svc/GetPackageInfo 例外是:
找不到与绑定 WebHttpBinding 的端点的方案 https 相匹配的基地址。注册的基地址方案是[http]。
这很烦人,因为我没有请求 HTTPS-URL。
现在,当我将服务拆分为两个时,HTTP 访问也可以在未安装 SSL 证书的 IIS 上运行:
<服务名称=“Blubb.ClientService”> <端点绑定=“webHttpBinding”绑定配置=“webBindingConfig”behaviorConfiguration=“webBehaviour” 合同=“Blubb.Contracts.IClientService”/>
<服务名称=“Blubb.ClientServiceSecure”>
<端点绑定=“webHttpBinding”绑定配置=“sslWebBindingConfig”行为配置=“webBehaviour” 合同=“Blubb.Contracts.IClientService”/>
现在的问题是客户端必须使用两个不同的端点,而不仅仅是更改协议。我们有一个系统,客户可以根据他们的安全需求通过我们的配置工具打开 SSL。但我不想强迫他们更改 WCF 服务的 web.config。
I have a WCF-Service configured with two endpoints using webHttpBinding, one for http and the other for https. They use the same address, the endpoints just differ by the used protocol:
<services>
<service name="Blubb.ClientService">
<endpoint binding="webHttpBinding" bindingConfiguration="webBindingConfig" behaviorConfiguration="webBehaviour"
contract="Blubb.Contracts.IClientService"/>
<endpoint binding="webHttpBinding" bindingConfiguration="sslWebBindingConfig" behaviorConfiguration="webBehaviour"
contract="Blubb.Contracts.IClientService"/>
</service>
<services>
using the following behaviours and bindings:
<behaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webBindingConfig">
<security mode="None"/>
</binding>
<binding name="sslWebBindingConfig">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
Both endpoints work fine when I have the certificate installed on IIS 6.
When the certificate is not installed, the HTTPS-Endpoint certainly won't work. But the HTTP-Endpoint doesn't work either. It fails with an irritating exception: when I access the service with http://localhost:8080/ClientManagement/ClientService.svc/GetPackageInfo the exception is:
Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].
which is irritating because I didn't request an HTTPS-URL.
Now when I split the service into two, the HTTP-Access also works on the IIS on which the SSL-Certificate is not installed:
<services>
<service name="Blubb.ClientService">
<endpoint binding="webHttpBinding" bindingConfiguration="webBindingConfig" behaviorConfiguration="webBehaviour"
contract="Blubb.Contracts.IClientService"/>
</service>
<service name="Blubb.ClientServiceSecure">
<endpoint binding="webHttpBinding" bindingConfiguration="sslWebBindingConfig" behaviorConfiguration="webBehaviour"
contract="Blubb.Contracts.IClientService"/>
</service>
</services>
The problem now is that the client has to use two different endpoints instead of just changing the protocol. We have a system where the customer can turn on SSL via our Configuration-Tool depending on their security needs. But I don't want to force them to change the web.config of the WCF-Service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论