首页 > 解决方案 > 仅在 HTTPS 上托管时出现 RESTful WCF 服务错误

问题描述

几年前,我关注了这篇RESTful WCF Services with No svc file 和 No config非常有用的文章,介绍了在不使用 svc 文件的情况下设置 RESTful WCF 并且工作得像个梦。但是最近我不得不将站点移到 HTTPS(仍然保留 HTTP 进行测试)并且一切正常,直到我删除了 HTTP 站点的绑定并且我收到一条错误消息,指向网络中的这个条目.config:

<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>

删除条目可修复错误,但会停止此设置提供的自动生成的帮助页面。

以下是引发的 2 个错误的简短片段:

异常:System.ServiceModel.ServiceActivationException:由于编译期间出现异常,无法激活服务“/myService”。异常消息是:找不到与绑定 WebHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [https].. ---> System.InvalidOperationException:找不到与绑定 WebHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 [https]。

异常:System.ServiceModel.ServiceActivationException:由于编译期间出现异常,无法激活服务“/MyService”。异常消息是:在您的配置中检测到端点引用周期。必须删除以下引用循环:webHttpEndpoint/、webHttpEndpoint/。(...\web.config 第 222 行)。---> System.Configuration.ConfigurationErrorsException:在您的配置中检测到端点引用周期。必须删除以下引用循环:webHttpEndpoint/、webHttpEndpoint/。(...\web.config 第 222 行)

希望有人之前已经看到并解决了这个问题。

标签: vb.netrestwcf

解决方案


想通了,所以我需要一个绑定,更新后的 web.config 是这样的:

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


<standardEndpoints>
  <webHttpEndpoint>
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />                 
  </webHttpEndpoint>
</standardEndpoints>

推荐阅读