calling a web service using WCF over Http and Https calling a web service using WCF over Http and Https asp.net asp.net

calling a web service using WCF over Http and Https


I found an answer digging around MSDN.

In my case, I was using a custom binding:

<customBinding>    <binding name="jsonpBinding">        <jsonpMessageEncoding/>        <httpTransport manualAddressing="true"/>    </binding></customBinding>

That was referenced in the service

<services>    <service name="{YourInfoHere}">        <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/>    </service></services>

Adding a second binding that used httpsTransport and then a second service that used that binding did the trick. Final output:

    <services>        <service name="{YourInfoHere}">            <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBinding" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/>            <endpoint address="" binding="customBinding" bindingConfiguration="jsonpBindingHttps" behaviorConfiguration="{YourInfoHere}" contract="{YourInfoHere}"/>        </service>    </services>    <bindings>        <customBinding>            <binding name="jsonpBinding">                <jsonpMessageEncoding/>                <httpTransport manualAddressing="true"/>            </binding>            <binding name="jsonpBindingHttps">                <jsonpMessageEncoding/>                <httpsTransport manualAddressing="true" />            </binding>        </customBinding>    </bindings>

May not be ideal, but it works. These were the only changes I made to make SSL work. Since it is all in the binding & transport, the code remains the same.

Relevant MSDN links:

  1. Custom Binding: http://msdn.microsoft.com/en-us/library/ms731377.aspx
  2. HttpTransport: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.aspx
  3. HttpsTransport: http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httpstransportbindingelement.aspx


I am assuming that you are using basichttpbinding. Then you need to do two things:

  • change the address to https :)
  • set the security mode to transport


I understand that you are using WCF to build the client, that connects to a remote web service, over HTTPS.

To do this, just modify the client-side config file for the WCF-powered app, replacing http://server.address with https://server.address, in configuration/system.serviceModel/client/endpoint/@address . like so:

<configuration>  <system.serviceModel>    ...    <client>        <!-- change only the address string -->        <endpoint address="https://server.name/Whatever"            everything.else.stays.the.same />    </client>  </system.serviceModel></configuration>

(The path to the config file varies according to the regular .NET rules: whether it is an ASPNET app, or a service, or etc.)

OR you can set the address explicitly in code:

    // instantiate new proxy to web service    var svc= new ServiceClient();    var e = svc.Endpoint;    e.Address = new System.ServiceModel.EndpointAddress("https://server.address/JavaServiceUri");

I strongly advise you to make the address configurable, and not hard-code it. That does not mean it must be stored in app.config, but it should be changeable. The proxy, too.