Search code examples
web-serviceshttpswshttpbinding

Client App with WsHttpBinding gets "no endpoint listening at..."


I have a client application which talks to our Web Service hosted on a server (we'll call it hostServer). My client application can build and connect fine using basicHttpBinding. However, I'm trying to impliment wsHttpBinding for security reasons.

Last week before lunch I could swear it was working with a hardcoded certificate. Came back from lunch, checked in my code and now it won't run. I keep getting "There was no endpoint listening at https://hostServer:1234/Service.svc/MyServiceName that could accept the message. This is often caused by an incorrect address or SOAP action.". I've tried re-checking my settings, retracing my steps, but can't seem to get back to the functioning state I was in.

I am using a ServiceReference with an address of "https ://hostServer:1234/Service.svc?singleWsdl". I can navigate to "https ://hostServer:1234/Service.svc" without a problem and view the Wsdl.

My client code is

WSHttpBinding wsBinding = new WSHttpBinding(SecurityMode.Transport);
wsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

Client = new MyServiceName(wsBinding, new EndpointAddress(endpoint));

Client.ClientCredentials.ClientCertificate.SetCertificate(
  StoreLocation.CurrentUser,
  StoreName.My,
  X509FindType.FindBySubjectName,
  "localCertName");

 Client.ChangePassword("test_user", "pt", "a1");

My value endpoint = https://hostServer:1234/Service.svc/MyServiceName

My IIS site is set up with Binding for Http and Https (with correct IP & Port ID)

I really need to get this code working before taking off (my wife is due with our second child any day). I've been working to debug this now for 2 days, in addition to the time it took me to stand it up as is. Please help.


Solution

  • So I was finally able to get this working again. Listing what steps were performed below in hopes that it might help someone else.

    On IIS Server (IIS Manager):

    Modified "Site Bindings" to include HTTP & HTTPS (w/different Port Numbers)

    Set SSL setting to "Require SSL" and "Accept"

    On IIS Server (Web.Config):

    Added

    <bindings> 
      <wsHttpBinding> 
        <binding name="wsHttpEndpointBinding"> 
          <security mode="Transport"> 
            <transport clientCredentialType ="Certificate"/> 
          </security> 
        </binding> 
      </wsHttpBinding> 
    </bindings>
    

    to the "System.ServiceModel" tag.

    Also, added 'bindingConfiguration="wsHttpEndpointBinding"' to my endpoint.

    In Code

    Updated Endpoint address to use that generated on the IIS Server.

    Used the following code for creating the endpoint

     WSHttpBinding wsBinding = new WSHttpBinding(SecurityMode.Transport); 
        wsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 
        Client = new ServiceClient(wsBinding, new EndpointAddress(endpoint)); 
        Client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMac‌​hine, StoreName.My, X509FindType.FindByIssuerName, certName);