Configure WCF 4 with routing (global.asax) for http and https endpoints

I am still new to wcf and not too well informed on .net in general. I have a WCF 4 web service that uses the global.asax global routing approach and a very simplified web.config using the standard endpoint method. This wcf service works as an app with a default website on iis 7.5 currently. I need it to support both http and https interfaces, if possible. If it's too complicated, then just https. What is the best way to maintain the current approach?

The contents of the global.asax.cs and web.config files are pretty simple:

public class Global : HttpApplication { void Application_Start(object sender, EventArgs e) { RegisterRoutes(); } private void RegisterRoutes() { // Edit the base address of Service1 by replacing the "ippay" string below RouteTable.Routes.Add(new ServiceRoute("myservice", new WebServiceHostFactory(), typeof(myservice))); } } <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" contentTypeMapper="myservice.Util.RawMapper,myservice"> </standardEndpoint> </webHttpEndpoint> </standardEndpoints> 

+7
ssl web-services wcf
source share
2 answers

I found the answer: you just need to put this fragment in your web.config in the serviceModel tag:

 <bindings> <webHttpBinding> <binding> <security mode="Transport" /> </binding> </webHttpBinding> </bindings> 

Thanks to this post: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/1dd991a1-e32f-4035-a406-994729858b40

My full web.config:

 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </modules> </system.webServer> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <bindings> <webHttpBinding> <binding> <security mode="Transport" /> </binding> </webHttpBinding> </bindings> <standardEndpoints> <webHttpEndpoint> <!-- Configure the WCF REST service base address via the global.asax.cs file and the default endpoint via the attributes on the <standardEndpoint> element below --> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"> <security mode="Transport" > </security> </standardEndpoint> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> </configuration> 
+9
source

The above works if you don't need HTTP and HTTPS. In my case, I want both because some services require SSL (authentication), while others are not like the information they provide is not sensitive. The authentication service implementation checks and refuses to respond if the request is not received from the https scheme.

The following configuration works if you want to configure both HTTP and HTTPS on the same endpoint.

 <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <webHttpBinding> <binding> <security mode="Transport" /> </binding> <binding name="UnsecureBinding"></binding> </webHttpBinding> </bindings> <protocolMapping> <add scheme="http" binding="webHttpBinding" bindingConfiguration="UnsecureBinding" /> </protocolMapping> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" /> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> 
+3
source

All Articles