【问题标题】:Configure SSL binding for RESTful WCF. How?为 RESTful WCF 配置 SSL 绑定。如何?
【发布时间】:2012-03-03 18:51:13
【问题描述】:

我当前的配置如下:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!--Set limit to 5 megabytes-->
        <standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="5242880">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />

        </standardEndpoint>

      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

当我为我的网站配置了http 和 https 绑定时,此方法有效。

我通过 https 连接到服务,一切正常。

现在我想完全删除 IIS 上的 http 绑定。我开始收到这样的错误:

找不到与方案 http 匹配的基地址 具有绑定 WebHttpBinding 的端点。注册的基地址方案 是 [https]。

[InvalidOperationException: 找不到匹配的基地址 具有绑定 WebHttpBinding 的端点的方案 http。挂号的 基地址方案是 [https]。]
System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri,绑定绑定,UriSchemeKeyedCollection 基本地址)+16582113
System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElement serviceEndpointElement、ServiceHostBase 主机、ServiceEndpoint 端点)+117
System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(标准端点元素 标准端点元素、服务端点元素 serviceEndpointElement、ContextInformation 上下文、ServiceHostBase 主机,ServiceDescription 描述,ServiceEndpoint& 端点, 布尔省略SettingEndpointAddress) +937
System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement serviceEndpointElement、ContextInformation 上下文、ServiceHostBase 主机,ServiceDescription 描述,布尔值 省略SettingEndpointAddress) +8728167
System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost 主机,IDictionary`2 实施合同,字符串 multipleContractsErrorMessage,字符串标准端点种类)+982
System.ServiceModel.Web.WebServiceHost.OnOpening() +311
System.ServiceModel.Channels.CommunicationObject.Open(时间跨度 超时)+612
System.ServiceModel.HostingManager.ActivateService(字符串 标准化虚拟路径)+255
System.ServiceModel.HostingManager.EnsureServiceAvailable(字符串 normalizedVirtualPath) +1172

[ServiceActivationException: 服务 '/DEMO/mobile' 不能 由于编译期间的异常而激活。例外 消息是:找不到与方案 http 匹配的基地址 具有绑定 WebHttpBinding 的端点。注册基址 方案是 [https]..] System.Runtime.AsyncResult.End(IAsyncResult 结果)+901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult 结果)+178702
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136

我为 WCF 找到了一堆示例,但 REST WCF 在配置方面看起来不同,我想了解它的原因为什么。从我的配置来看 - 它根本不应该通过 SSL 工作,但它确实在存在 https 绑定时工作..

【问题讨论】:

  • 如果您想删除 IIS 上的 http 绑定,只需右键单击网站选择编辑绑定选项并从绑定列表中删除 http 协议。应该够了
  • 没有。如果我这样做 - 我会收到我发布的错误。
  • 您是否尝试使用 http 访问该 url?
  • 不。我只想离开 HTTPS。如果我删除 http 绑定,我会收到此错误
  • 您能否创建一个新网站并仅映射 https 绑定并将您的应用程序部署到该网站并检查是否可行?

标签: c# .net wcf rest web-config


【解决方案1】:

按照错误所说的去做...修复你的绑定

 <services>
      <service name="service" behaviorConfiguration="serviceBehavior">
        <endpoint address="" binding="webHttpBinding"
              bindingConfiguration="https"
contract="IContract" behaviorConfiguration="endpointBehavior">
        </endpoint>
      </service>
    </services> 

<bindings>
 <webHttpBinding>
  <binding name="https" maxReceivedMessageSize="65536">
    <security mode="Transport" />
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />

  </binding>
 </webHttpBinding>
</bindings>

【讨论】:

  • 这实际上不是问题的解决方案,因为原始发布者使用的是标准端点,而这个答案需要一个明确的端点。对于可以轻松切换到显式端点的人,我想没关系。不过我不能,所以我没有答案。
【解决方案2】:

接受的答案对我不起作用,因为我需要保留标准端点元素。我能够通过在我的 Web.config 中添加 &lt;webHttpBinding&gt; 部分来删除我的 http 绑定并仅将 https 绑定保留在 IIS 中

确保不要在&lt;binding&gt;上设置name属性,否则这将不起作用

我的 Web.config 的相关部分:

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <bindings>
      <webHttpBinding>
        <binding>
          <!-- Comment out the following line if HTTP is used. If HTTPS is used, leave it enabled -->
          <security mode="Transport"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="false" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

【讨论】:

    【解决方案3】:

    试试这个

    <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <!--Set limit to 5 megabytes-->
        <standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="5242880">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
    
        </standardEndpoint>
        <security mode="Transport" />
      </webHttpEndpoint>
    </standardEndpoints>
    </system.serviceModel>
    

    【讨论】:

    • 元素 'webHttpEndpoint' 的子元素 'security' 无效。预期的可能元素列表:'standardEndpoint, remove, clear'。
    猜你喜欢
    • 2011-04-04
    • 2011-02-11
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多