Adding WCF Service Reference with https endpoint

Chris Klepeis picture Chris Klepeis · Nov 7, 2011 · Viewed 69.4k times · Source

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. 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. How can I setup my service / client to force https so that it correctly sets the endpoint?

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. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

I can, however, see that endpoint in IE, and am debugging locally. 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

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?

Answer

Nick Nieslanik picture Nick Nieslanik · Nov 7, 2011

You need to change your binding to use transport security to use HTTPS

Transport Security

Your server side binding should be configured for https as well as client:

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