Quantcast
Channel: Tom's Blog » Windows
Viewing all articles
Browse latest Browse all 10

WCF Services and Multiple Bindings in IIS

$
0
0

When you have mutlitple bindings in IIS and have a WCF Service defined you may get the bellow error:

“This collection already containes an address with scheme http. There can be at most one address per scheme in this collection.”

This happens when you have mutlitple bindings on the IIS Web Site i.e. HTTP and HTTPS.

If you have .NET 4.0 installed and are on Server 2008 or later you can add a directive to your web.config to allow multiple bindings.

Add multipleSiteBindingsEnabled=”true” to serviceHostingEnvironment like below:

<serviceHostingEnvironment aspNetCompatibilityEnabled=”true” multipleSiteBindingsEnabled=”true”>

Then you can add multiple endpoints to the service definition.

So if you want your service to work on HTTP and HTTPS you need 2 endpoints, the HTTP endpoint can look like this:

<endpoint address=”” behaviorConfiguration=”KBServiceAspNetAjaxBehavior” binding=”webHttpBinding” contract=”CustomerService” />

Now your HTTPS endpoint needs to be bound to HTTPS by using bindingConfiguration directive:

<endpoint address=”” behaviorConfiguration=”KBServiceAspNetAjaxBehavior” binding=”webHttpBinding” bindingConfiguration=”webBindingHTTPS” contract=”CustomerService” />

Now define your bindingConfiguration:
<bindings>
           <webHttpBinding>
              <binding name=”webBindingHTTPS”>
                  <security mode=”Transport”></security>
              </binding>
           </webHttpBinding>
        </bindings>
If you set Security mode to transport this means the binding will be encrypted and bound to HTTPS.

You should now be able to access you WCF services on both HTTP and HTTPS

The post WCF Services and Multiple Bindings in IIS appeared first on Tom's Blog.


Viewing all articles
Browse latest Browse all 10

Trending Articles