支持HTTP或HTTPS Web.Config WCF服务

时间:2018-03-09 16:04:52

标签: c# web-services wcf web-config

我想要一个支持HTTP或HTTPS的WCF服务。 Link1link2非常有用,我设法修改了web.config以适用于HTTP和HTTPS

    <service name="Service">
       <endpoint address="" contract="IService" binding="webHttpBinding" bindingConfiguration="wbBind" behaviorConfiguration="web" />
       <endpoint address="" contract="IService" binding="webHttpBinding" bindingConfiguration="wbsBind" behaviorConfiguration="web" />
  </service>

  <binding name="wbBind">
       <security mode="None"></security> 
  </binding>
  <binding name="wbsBind">
      <security mode="Transport"></security> 
  </binding>

当我有两个IIS绑定时,这很好用 Site bindings

但是如果我删除其中一个绑定(例如http) Only https binding

然后https也将停止工作(或反过来)。这可以修复吗?

1 个答案:

答案 0 :(得分:0)

只有http绑定配置如下:

    <service name="Service">
       <endpoint address="" contract="IService" binding="webHttpBinding" bindingConfiguration="wbBind" behaviorConfiguration="web" />
  </service>

  <binding name="wbBind"/>

请记住,您应该更改网络配置,以便只拥有http或https绑定。