简体   繁体   中英

WCF ServiceHost BaseAddresses does not contain all IIS host header values, when multiple Host Headers set in IIS

I have a WCF service that has bee working for a long time, hosted in IIS6 (Windows Web Server 2003).

I am trying to add a 2nd host header value in IIS (previously there was only 1).

So now in IIS, lets say I have configured:

IP: All Available, Port: 80, Host: x.test.com
IP: All Available, Port: 80, Host: y.test.com

In my application, I have this WCF config property set:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>

And I have a custom ServiceHostFactory :

public class MySuperServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        //...
    }
}

In the parameter Uri[] baseAddresses , WCF seems to only ever pass me whatever the first value is in the IIS configuration. So for this example, baseAddresses is a Uri[1] with the one value http://x.test.com/MyService.svc .


The same thing happens if I specify HTTP and HTTPS host headers in IIS. So back to the same example, lets say for HTTP traffic we set:

IP: All Available, Port: 80, Host: x.test.com
IP: All Available, Port: 80, Host: y.test.com

And for SSL traffic we run the command:

cscript.exe c:\\Inetpub\\AdminScripts\\adsutil.vbs set /w3svc/12345/SecureBindings ":443:secureA.test.com" ":443:secureB.test.com"

So now my site should have 4 possible addresses.

However now WCF just passes me the first host from each type of connection, so my Uri[] now contains 2 elements:

http://x.test.com/MyService.svc
https://secureA.test.com/MyService.svc

Anyone have any insight as to why this happens?


Edit:

This link " How can WCF support multiple IIS Binding specified per site ? " at the very bottom says:

Solution in .Net Fx4.0: BaseAddressPrefixFilters

Beta2 Fix

In the current Beta2 release of the .NET Framework, we added support for multiple site binding . Just set the binding in IIS site and the service will inherit the address

Final RTM Fix

In the final bits, we decided to make it an opt-in due to application compatability reasons. In order to enable multiple site binding, you need to set multipleSiteBindingEnabled to true in your application. Multiple site binding is supported only for Http protocol. The address of endpoints in the configuration file need to be complete URI. When porting your 3.0 or 3.5 workaround to 4.0 you need to keep this particular aspect.

 <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

That very last bit is what I am doing. I am using .NET4's added ability to set multiple host headers in IIS, with multipleSiteBindingsEnabled="true" set in my configuration.

This actually works fine if you leave the rest of WCF alone and let it do its default thing for constructing the service endpoints.

However, my issue is that all the multiple host headers aren't actually passed in to a custom ServiceHostFactory implementation, so it seems difficult or impossible to manually set up your own endpoints on all base addresses.

Perhaps this is just a bug in .NET 4?

In your custom classes are you manually adding the other end points? I do believe the way it is engineered you need to do so manually...

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

With this notion it seems that if the EndPoint it is the config then it will be added for you. Since your config is empty you must add the endpoint's manually.

See WCF Self Host Service - Endpoints in C#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM