简体   繁体   English

使用https端点添加WCF服务引用

[英]Adding WCF Service Reference with https endpoint

My WCF service application works over http and https, however, when I add a service reference (with the https url) to it in my client, Visual Studio 2010 sets the endpoint in the config file to http. 我的WCF服务应用程序通过http和https工作,但是,当我在客户端向其添加服务引用(使用https url)时,Visual Studio 2010将配置文件中的端点设置为http。 It doesn't appear to be as simple as changing that config endpoint to https since there are multiple files behind the scenes doing things with the xsd's and reference the http endpoint. 它似乎并不像将配置端点更改为https那么简单,因为幕后有多个文件使用xsd进行操作并引用http端点。 How can I setup my service / client to force https so that it correctly sets the endpoint? 如何设置我的服务/客户端以强制https以便正确设置端点?

When I try to manually change the endpoint in the config file and set security mode to "Transport" I get this error: 当我尝试手动更改配置文件中的端点并将安全模式设置为“传输”时,我收到此错误:

Exception Message: There was no endpoint listening at https://myservice/AvailabilityService.svc that could accept the message. 异常消息: https://myservice/AvailabilityService.svc上没有可以接受消息的端点监听。 This is often caused by an incorrect address or SOAP action. 这通常是由错误的地址或SOAP操作引起的。 See InnerException, if present, for more details. 有关更多详细信息,请参阅InnerException(如果存在)。

I can, however, see that endpoint in IE, and am debugging locally. 但是,我可以在IE中看到该端点,并在本地进行调试。 After I add my service reference with https and search the solution for its http equivolent, it finds a wsdl file referencing http, a configuration.svcinfo, and a configuration91.svcinfo that utilizes the http url instead of https 在我使用https添加我的服务引用并搜索解决方案的http等效之后,它会找到一个引用http的wsdl文件,一个configuration.svcinfo和一个使用http url而不是https的configuration91.svcinfo

Here's my server side config: 这是我的服务器端配置:

<?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>

.. And the client side config: ..和客户端配置:

<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>

Perhaps I'm better off manually consuming the services in code? 也许我最好手动使用代码中的服务?

You need to change your binding to use transport security to use HTTPS 您需要更改绑定以使用传输安全性来使用HTTPS

Transport Security 运输安全

Your server side binding should be configured for https as well as client: 您的服务器端绑定应配置为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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM