【问题标题】:Support HTTP or HTTPS Web.Config WCF Service支持 HTTP 或 HTTPS Web.Config WCF 服务
【发布时间】:2018-03-09 16:04:51
【问题描述】:

我想要一个支持 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 也将停止工作(或相反)。这可以解决吗?

【问题讨论】:

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


    【解决方案1】:

    只有 http 绑定配置会是这样的:

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

    请记住,您应该更改 Web 配置以仅使用 http 或 https 绑定。

    【讨论】:

    • 我知道配置应该如何查找只是 http...或只是 https;而且我也知道支持 http 和 https(如果 IIS 中的站点绑定数量等于 web.config 中服务的端点数量)现在,我想要的是一个同时支持 http 和https,无论 IIS 中的站点绑定数量如何。因此,如果用户具有 http 站点绑定,则该网站将使用 http;如果他有 https 绑定,它将与 https 一起使用;如果他有 http 和 https,它可以同时使用。
    • 这很简单。只需在您的 iis 中设置 http 和 https 绑定,然后您就可以开始了。请记住,如果您只想要 http,则应删除 https 部分。没有办法让它按照你想要的方式工作。你可以在 web api 中实现,但在 wcf 中不行。
    猜你喜欢
    • 2015-09-15
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多