Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling a web service using WCF over Http and Https

In our project we have a java web service that runs over http and https. We want to use http internally and https for the external version of our web app.

So we've created the proxy class in our application and we have setup the binding for http in the web/app.config and all works fine.

What changes would we need to make to the code and the configuration to support https for the same service in our external application? If possible please supply code snippets to explain!

like image 947
Lewis Avatar asked Jun 04 '09 15:06

Lewis


People also ask

How can I combine the WCF services config for both http and https in one web config?

You need to enable both HTTP & HTTPS in IIS. In IIS 7.5, go to your site and click on Bindings under Edit Site Action. Ensure that both http & https have been added. Then you need to create a binding for HTTP under <basicHttpBinding> , with security mode set to none.

Is WCF and Web service same?

Web services support only one protocol- HTTP and HTTPS during communication, but WCF supports more protocols like- HTTP, TCP, and MSMQ that can be extended for a comprehensive solution, reliable session, and transactions. It signifies WCF is more adaptable to work together for a variety of software.


2 Answers

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
like image 185
jeffreypriebe Avatar answered Sep 18 '22 07:09

jeffreypriebe


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
like image 25
Shiraz Bhaiji Avatar answered Sep 22 '22 07:09

Shiraz Bhaiji