Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying WCF Service with both http and https bindings/endpoints

I've written a WCF web service for consumption by a Silverlight app. Initially, the service only required a basic http binding. We now need to be able to deploy the service for use under both http and https. I've found some settings for web.config that allow me to do this as follows:

<system.serviceModel>   <behaviors>     <endpointBehaviors>       <behavior name="SilverlightFaultBehavior">         <silverlightFaults />       </behavior>     </endpointBehaviors>     <serviceBehaviors>       <behavior name="CxtMappingWebService.CxtMappingWebServiceBehavior">         <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />         <serviceDebug includeExceptionDetailInFaults="True" />       </behavior>     </serviceBehaviors>   </behaviors>   <bindings>     <basicHttpBinding>       <binding name="SecureHttpBinding">         <security mode="Transport" />       </binding>       <binding name="BasicHttpBinding">         <security mode="None" />       </binding>     </basicHttpBinding>   </bindings>   <services>     <service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">       <endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />       <endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />     </service>   </services> </system.serviceModel> 

Unfortunately, however, there's a problem with this.

This web service needs to be deployed to hundreds of our customers' servers, and not all of them will be using https. Deploying it to a server that doesn't have an https binding set up in IIS causes it to fail. Is there a way to have both of these bindings in the web.config by default without it dying if there's not an https binding set up in IIS?

We've got a possible solution for this problem, but it doesn't really fit well with our deployment requirements.

Has anybody else encountered anything like this before, and how did you resolve it?

like image 638
Zann Anderson Avatar asked Jan 25 '11 19:01

Zann Anderson


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.

Can we have multiple endpoints in WCF?

WCF allow us to give multiple base addresses for each type of protocol. And at the run time corresponding endpoint will take the base address. So you can expose IService1 on multiple EndPoint with more than one binding as below.


1 Answers

The accepted answer on this page is not of much use if you don't use an installer. The correct answer lies in a later edit by the OP himself, all one needs to do is bind both http and https ports in IIS and then use the configuration below.

            <service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">               <endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />               <endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />               <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />             </service> 

That worked just fine for me!

like image 92
Krishnan Venkiteswaran Avatar answered Oct 01 '22 06:10

Krishnan Venkiteswaran