c# - 如何在不创建新客户端或破坏现有客户端的情况下制作只有 HTTP 和 HTTPS 的 WCF 服务
问题描述
我有一个使用 basicHttpBinding 的 WCF 服务。它作为 HTTP 公开给许多客户端。
现在我们的要求是将此服务作为 HTTPS 公开给少数新客户端,同时我们不应该破坏通过 http 消费的现有客户端。
我遇到了以编程方式检测安全类型然后公开,但是还有其他更好更简单的方法吗?只是使用端点配置等?
我对这些领域还很陌生,请举个例子
解决方案
是的,正如您在两天前为我们的一些服务所做的配置中提到的那样,有一个更好的解决方案。
添加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
使用默认的 basic 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>
推荐阅读
- python - 无法从“easygui”模块导入“floatbox”
- c# - 2个属性浮动范围Asp .Net Core之间的自定义验证
- scrapy - scrapy 站点地图蜘蛛没有提供预期的结果
- apache-spark - Spark 将 Hive 连接到 HDFS 与 Spark 直接连接 HDFS 并在其顶部连接 Hive?
- npm-install - npm 错误!对 https://registry.npmjs.org/ngx-pagination 的请求失败,原因:getaddrinfo EAI_AGAIN registry.npmjs.org registry.npmjs.org:443
- c# - 更改其他文本框时 WPF 绑定文本框值未更新
- ruby-on-rails - 在Rails中erb的文本字段中显示模型的所有ID
- python-3.x - 即使输入相同,相同的代码在主函数和用户定义的函数中使用时也会给出不同的输出
- javascript - D3:条形图的文本不出现
- javascript - 使用伊斯坦布尔插件构建代码时出错