Gabriel Graves
Gabriel Graves

Reputation: 1785

WCF Won't Work Over HTTPS

I have looked through all of the other solutions and none of them are working. I am hosting a WCF service using IIS. The following is my web.config (the default for when I added a WCF service):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <customErrors mode="Off" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

All is good and I can access my wcf service in the browser using http://www.domain.com/path/service.svc and https://www.domain.com/path/service.svc - now I add a web reference to https://www.domain.com/path/service.svc in a windows console application and the following is in my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="defaultBasicHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://www.domain.com/path/service.svc" binding="basicHttpBinding" bindingConfiguration="defaultBasicHttpBinding" contract="DomainExt.IExt" name="BasicHttpBinding_IExt" />
    </client>
  </system.serviceModel>
</configuration>

The following code is what I am using to test the service:

public static String DoPing()
{
     ExtClient client = new ExtClient("BasicHttpBinding_IExt", "https://www.domain.com/path/service.svc");
     return client.DoPing();
}

After I run this I get the following exception:

There was no endpoint listening at https://www.domain.com/path/service.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

The inner-exception sates:

"The remote server returned an error: (404) Not Found."

This service works fine over http but fails on https. How can I fix this? Please note that I'm accessing this service using Windows Console and NOT through ASP.NET; ASP.NET is only hosting the WCF service.

Upvotes: 3

Views: 1064

Answers (1)

Mark B
Mark B

Reputation: 1186

Try setting httpsGetEnabled="true" rather than httpGetEnabled

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpsGetEnabled="true" />

EDIT: I'm also curious why you chose the BasicHttpBinding if you're using SSL. Why not use the WsHttpBinding?

EDIT2: Are you missing a <services> node in your host config file? I wouldn't think you could create a client without one. You can right click on your app.config file and configure it there... Something like this:

    <services>
        <service behaviorConfiguration="MyServiceBehavior" name="MyService">
            <endpoint address="" binding="defaultBasicHttpBinding" bindingConfiguration="basicBinding" contract="IMyService" />

        </service>
    </services>
    <behaviors> 
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">

Upvotes: 2

Related Questions