title: WCF Service over SSL
body: <p>I'm encountering a problem in setting up a WCF service over SSL. The service is very simple which only returns "Hello World!". The message could be received by the client over HTTP but not over HTTPS. I guess it's the problem of my web.config setting but i can't figure it out.</p>
  
  <p>Besides, I could visit the HelloWorld.svc page on the server by browser but fail with my console program and WCF Test Client as well.</p>
  
  <p>Here's the error message:</p>
  
  <pre><code>System.ServiceModel.EndpointNotFoundException: There was no endpoint listening a
  t https://fyp-pc13:997/HelloWorldService/HelloWorld.svc that could accept the me
  ssage. This is often caused by an incorrect address or SOAP action. See InnerExc
  eption, if present, for more details. ---&gt; System.Net.WebException: The remote s
  erver returned an error: (404) Not Found.
     at System.Net.HttpWebRequest.GetResponse()
     at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
  nnelRequest.WaitForReply(TimeSpan timeout)
     --- End of inner exception stack trace ---
  </code></pre>
  
  <p>The content of my Web.config on the WCF server:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                  &lt;binding name="BasicHttpBinding_IHelloService" 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"&gt;
                      &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                          maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                    &lt;security mode="Transport"&gt;
                      &lt;transport realm ="" clientCredentialType="None" /&gt;
                    &lt;/security&gt;
                          &lt;!--&lt;transport clientCredentialType="None" proxyCredentialType="None"
                              realm="" /&gt;
                          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
                      &lt;/security&gt;--&gt;
                  &lt;/binding&gt;
              &lt;/basicHttpBinding&gt;
              &lt;wsHttpBinding&gt;
                &lt;binding name="WSHttpBinding_IHelloService"&gt;
                  &lt;security mode="Transport"&gt;
                    &lt;transport realm ="" clientCredentialType="None" /&gt;
                  &lt;/security&gt;
                &lt;/binding&gt;
              &lt;/wsHttpBinding&gt;
          &lt;/bindings&gt;
  
      &lt;services&gt;
          &lt;service name="HelloWorldService"&gt;
              &lt;!--&lt;endpoint address="https://localhost:997/HelloWorldService/HelloWorld.svc" binding="wsHttpBinding" contract="WcfService.HelloWorld" /&gt;--&gt;
              &lt;endpoint address="https://fyp-pc13:997/HelloWorldService/HelloWorld.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloService" contract="WcfService1.IHelloService" name="WSHttpBinding_IHelloService" /&gt;
              &lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/&gt;
          &lt;/service&gt;  
      &lt;/services&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
            &lt;serviceMetadata httpsGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
  
    &lt;/system.serviceModel&gt;
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The content of my ServiceReferences.ClientConfig:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                  &lt;binding name="BasicHttpBinding_IHelloService" 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"&gt;
                      &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                          maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                      &lt;security mode="Transport"&gt;
                          &lt;transport realm ="" clientCredentialType="None" /&gt;
                          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
              &lt;/basicHttpBinding&gt;
              &lt;wsHttpBinding&gt;
                &lt;binding name="WSHttpBinding_IHelloService"&gt;
                  &lt;security mode="Transport"&gt;
                    &lt;transport realm ="" clientCredentialType="None" /&gt;
                  &lt;/security&gt;
                &lt;/binding&gt;
              &lt;/wsHttpBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
              &lt;endpoint address="https://fyp-pc13:997/HelloWorldService/HelloWorld.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloService"
                contract="ServiceReference1.IHelloService" name="WSHttpBinding_IHelloService"&gt;
                &lt;identity&gt;
                    &lt;dns value="fyp-pc13" /&gt;
                &lt;/identity&gt;
              &lt;/endpoint&gt;
            &lt;endpoint address="mex" binding="mexHttpsBinding"
                contract="IMetadataExchange" /&gt;
          &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>HelloWorld.svc</p>
  
  <pre><code>    &lt;%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.HelloWorld" CodeBehind="HelloWorld.svc.cs" %&gt;
  </code></pre>
  
  <p>IHelloService.cs (Interface)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Runtime.Serialization;
  using System.ServiceModel;
  using System.ServiceModel.Web;
  using System.Text;
  
  namespace WcfService1
  {
      // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
      [ServiceContract]
      public interface IHelloService
      {
  
          [OperationContract]
          string GetData(int value);
  
          [OperationContract]
          CompositeType GetDataUsingDataContract(CompositeType composite);
  
          [OperationContract]
          string Hello();
  
          // TODO: Add your service operations here
      }
  
  
      // Use a data contract as illustrated in the sample below to add composite types to service operations.
      [DataContract]
      public class CompositeType
      {
          bool boolValue = true;
          string stringValue = "Hello ";
  
          [DataMember]
          public bool BoolValue
          {
              get { return boolValue; }
              set { boolValue = value; }
          }
  
          [DataMember]
          public string StringValue
          {
              get { return stringValue; }
              set { stringValue = value; }
          }
      }
  }
  </code></pre>
  
  <p>Driver (main)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using ConsoleApplication1.ServiceReference1;
  
  namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              try
              {
                  System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =&gt;
                  {
                      return true;
                  };
                  HelloServiceClient helloServiceClient = new HelloServiceClient();
                  string result = helloServiceClient.Hello();
                  if (result!=null)
                  {
                      Console.Out.WriteLine(result);
                  }
                  else
                  {
                      Console.Out.WriteLine("Fail");
                  }
              }
              catch (Exception e)
              {
                  Console.Out.WriteLine(e.ToString());
              }
  
          }
      }
  }
  </code></pre>