【问题标题】:Adding WCF Service Reference with https endpoint使用 https 端点添加 WCF 服务引用
【发布时间】:2011-12-23 17:36:33
【问题描述】:

我的 WCF 服务应用程序通过 http 和 https 工作,但是,当我在客户端中向它添加服务引用(使用 https url)时,Visual Studio 2010 将配置文件中的端点设置为 http。它似乎不像将配置端点更改为 https 那样简单,因为幕后有多个文件在使用 xsd 并引用 http 端点。如何设置我的服务/客户端以强制使用 https 以便正确设置端点?

当我尝试手动更改配置文件中的端点并将安全模式设置为“传输”时,我收到此错误:

异常消息:没有端点监听 https://myservice/AvailabilityService.svc 可以接受 信息。这通常是由不正确的地址或 SOAP 操作引起的。 有关详细信息,请参阅 InnerException(如果存在)。

但是,我可以在 IE 中看到该端点,并且正在本地调试。在我使用 https 添加我的服务引用并搜索其 http 等效项的解决方案后,它会找到一个引用 http 的 wsdl 文件、一个 configuration.svcinfo 和一个使用 http url 而不是 https 的 configuration91.svcinfo

这是我的服务器端配置:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

.. 和客户端配置:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IAvailabilityService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://myservice/AvailabilityService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAvailabilityService"
          contract="PaymentAvailabilityService.IAvailabilityService"
          name="BasicHttpBinding_IAvailabilityService" />
    </client>
  </system.serviceModel>

也许我最好手动使用代码中的服务?

【问题讨论】:

    标签: .net wcf ssl https endpoint


    【解决方案1】:

    您需要更改绑定以使用传输安全来使用 HTTPS

    Transport Security

    您的服务器端绑定应配置为 https 以及客户端:

    <bindings>
      <basicHttpBinding>
        <binding name="httpsBinding" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="yourNamespace.YourService" behaviorConfiguration="yourBehaviors">
        <endpoint contract="yourNamespace.YourService" binding="basicHttpBinding" bindingConfiguration="httpsBinding" />
      </service>
    </services>
    

    【讨论】:

    • 感谢您似乎成功了。我想我的假设是错误的,即 WCF 服务应用程序在后台做了一些事情,而它在 WCF 服务库中更为明确。
    • @ChrisKlepeis - 很高兴为您提供帮助!我认为在您的场景中,它正在做最基本的事情,即使用 std 开箱即用设置打开一个 basichttpbinding。您可以通过 https 访问 MEX 点,因为您在元数据行为中启用了该点。
    猜你喜欢
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多