Base addresses and IIS/WAS hosted services

If you have ever hosted a WCF service in IIS/WAS then you know that the .svc file for your service is the base address.  For example, if you create a web site project called MyService using the WCF Service template, then your base address for that service will be https://localhost/MyService/Service.svc.  That is why there is not a base address specified in the configuration for your service.

image 

It is also why the default service endpoint (wsHttpBinding) you get from Visual Studio's WCF Service template leaves the address property empty.  It is simply using the base address as the address for the endpoint.

image

Of course, any subsequent http endpoints you add will need a unique address relative to the base address in order for them to be reachable.

Now, what happens when you decide to add support for other non-http protocols (tcp for example) to your service hosted in IIS/WAS?  Do you need to specify a base address, such as net.tcp://localhost/MyService/Service.svc in order to use relative addresses in any tcp endpoints you add?  That is a question I debated with a good friend recently for which I took the position - yes, you would.  After all, how else are your relative addresses going to resolve to reachable address if there is not a base address? 

Well, it turns out I was wrong.  You do not have to add the base address for tcp (or any other protocol for that matter) because IIS/WAS is adding it for you when you enable these protocols for your service.  To verify this, I created a new Web Site project using the WCF Service template and added a method to return the BaseAddresses property from ServiceHost.

image

image 

Then, I used the WCF Test Client to test my service and as expected, I found the http and https base addresses for my service.

image

Next, I opened IIS Manager and enabled some other non-http protocols.

image

Without adding any endpoints to my services, I then re-ran the WCF Test Client and to my surprise the base addresses for these other protocols were already there!

image 

If I now add a tcp or pipe endpoint to my service, I can just enter a relative address for the endpoint because IIS/WAS has already provided the base address for these protocols.