gpt4 book ai didi

c# - 您如何设置 HTTP 和 HTTPS WCF 4 RESTful 服务?

转载 作者:太空狗 更新时间:2023-10-29 21:35:54 25 4
gpt4 key购买 nike

我正在尝试使用 WCF 4 来设置 RESTful Web 服务。我希望可以使用 HTTP 和 HTTPS 访问该服务。默认情况下,该服务是使用以下配置创建的,该配置适用于 http 但不适用于 https:

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" />
</protocolMapping>
</system.serviceModel>

然后我可以通过稍微更改配置来为服务启用 HTTPS:

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" bindingConfiguration="SecureWebBinding"/>
</protocolMapping>
</system.serviceModel>

我的问题是如何让服务与两者一起工作?

最佳答案

您应该尝试创建两个独立的端点。例如,

<system.serviceModel>
<services>
<service name="MyNameSpace.MyService">
<endpoint address="https://www.example.com/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="SecureWebBinding"
contract="MyNameSpace.IMyContract" />
<endpoint address="http://www.example.com/MyService.svc"
binding="basicHttpBinding"
contract="MyNameSpace.IMyContract" />
</service>

<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>

</services>
</system.serviceModel>

关于c# - 您如何设置 HTTP 和 HTTPS WCF 4 RESTful 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8059848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com