Freigeben über


Multiple Web Site Bindings

I've configured my web site in IIS with multiple bindings but my web service can no longer run because it refuses to start if there are multiple base addresses defined for the same URI scheme. How can I use the same configuration for both my web service and the rest of my web site?

Let's assume that you really do have a need to configure your web site with multiple bindings using the same URI scheme. Defining these multiple bindings is not an unreasonable thing to do. There are several legitimate reasons to publish your web site multiple times with the same scheme so let's look at how to fix the web service.

Obviously, if you don't actually need the multiple bindings, then removing the extra bindings is the simplest way to fix the problem. However, we're assuming that other parts of the web site require multiple bindings. Therefore, what we really need to do is find some way to remove the extra bindings just for the web service.

A direct way to remove the extra bindings without affecting the rest of the web site is to move the web service into its own web site with its own configuration. Then, we can leave the rest of the web site exactly as it is while giving the web service just the list of bindings it needs. However, that doesn't work if we need to use the same configuration for the web service as the rest of the web site. That means we need some indirect way to remove those extra bindings.

Let's assume now that we have no choice but to expose our web service to all the bindings. The part that actually blows up is the construction of the ServiceHost because the host is expecting a single base address per URI scheme. If we could intercept the list of bindings in between the time that IIS gives them to the web service and the ServiceHost is constructed, then we could save the day. There's only one piece of your code that runs during that time: execution of the ServiceHostFactory. That makes the decision easy. You'll create a custom ServiceHostFactory that filters the list of base addresses and everyone will be happy.

Next time: When to Use Remoting

Comments

  • Anonymous
    September 24, 2007
    What happens if I don't specify an EndpointIdentity for an EndpointAddress? I'm supposed to provide one