Enable SSL for my WCF service
Asked Answered
M

3

41

I have a WCF service that uses basicHttpbinding in development.

Now in product we want to use SSL, what changes do I have to make to force SSL connections only?

Mensch answered 8/1, 2009 at 21:14 Comment(1)
This is answered here: Hope it helps #2905383Jellaba
T
45

This page on MSDN explains WCF Binding Security.

http://msdn.microsoft.com/en-us/library/ms729700.aspx

The BasicHttpBinding class is primarily used to interoperate with existing Web services, and many of those services are hosted by Internet Information Services (IIS). Consequently, the transport security for this binding is designed for seamless interoperation with IIS sites. This is done by setting the security mode to Transport and then setting the client credential type. The credential type values correspond to IIS directory security mechanisms. The following code shows the mode being set and the credential type set to Windows. You can use this configuration when both client and server are on the same Windows domain.

C#

BasicHttpBinding b = new BasicHttpBinding();
b.Security.Mode = BasicHttpSecurityMode.Transport ;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;

Or, in configuration:

<bindings>   
   <basicHttpBinding>
            <binding name="SecurityByTransport">
               <security mode="Transport">
                 <transport clientCredentialType="Windows" />
                </security>
            </binding>   
   </basicHttpBinding> 
</bindings>

To enable SSL, without a login, set clientCredentialType to "None".

Options for security mode are:

None, Transport, Message, TransportWithMessageCredential and TransportCredentialOnly.

You can find more details at: http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpsecuritymode.aspx

Thinia answered 8/1, 2009 at 21:23 Comment(1)
so security mode of "transport" signifies SSL?Mensch
N
1

I just faced the same problem and found this MSDN article: How to: Configure an IIS-hosted WCF service with SSL At the end of the article you will find the xml configuration of the WebConfig file.

The solution worked just fine for me. One more thing to say, keep in mind that you need a REAL certificate for your release!

Nonprofit answered 9/1, 2013 at 7:57 Comment(0)
W
0

I think that if under your bindings where you have the <Security mode="Transport">, if you would change it to be <security mode="None">, you would be ok.

This is a copy of a code base that I'm working on and I tried that in-code, and it appears to be working.
I get the WSDL at least when I call the service, if that helps at all.

BasicHttpBinding basicBinding = new BasicHttpBinding();
if (RegistryConnectionStringFactory.UseSslForCommunications)
{
   basicBinding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
   basicBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
}
else
{
   basicBinding.Security.Mode = BasicHttpSecurityMode.None;
   basicBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
}
Warble answered 24/3, 2010 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.