Monday, January 12, 2009

How to get rid of in WCF WSDL

"Each XML Web Service needs a unique namespace in order for client applications to distinguish it from other services on the Web. By default, ASP.Net Web Services use for this purpose. While this suitable for XML Web Services under development, published services should use a unique, permanent namespace." (

By default WCF maps all service operations to the targetnamespace .
The problem with this approach occurs as soon as you as you need to uniquely indentify a service operation and you have more than just one service. e.g. in Biztalk or Microsoft Managed Service Engine.
Guess you have a 2 services both with the DoSomeThing() function. As both use the namespace for their operations, you can't uniquely indentify them.

To get rid of in your WSDL in WCF do the following:

1.) In your ServiceContract attribute constructor define the Namespace property.

[ServiceContract(Namespace = "")]

public interface IMyService

2.) For your ServiceClass create the ServiceBehavior attribute with Namespace property

[ServiceBehavior(Namespace = "")]

class MyService : IMyService

3.) In all your bindings set the bindingNamespace property

<endpoint binding="basicHttpBinding" bindingNamespace=""....


Mike said...

Thank you! I had missed the endpoint BindingNamespace and this was driving my nuts!!

Anonymous said...

Thanks from me too regarding 3rd point :)

Anonymous said...

Thanks for this but WTF?! Why no less than three places? the uber configurable WCF strikes again.

Arun PL said...


I hope this not required in WCF4

Anonymous said...

Excellent tips... solved my problem

Karol said...

Does it actually matter what the value of the namespace uri is ? I though it has to be the address of the web service like http://myserver.domain/mywebservice
or it does not matter ? If you have only one web service do you actually need to change the targetNamespace ?
Does the namespace uri have to reflect the location of the web service?
If the namespace has to reflect the location of the web service which will change depending on the server it is running on. In this case how can we change namespace in attributes without touching the code ?

elLoco said...

No the namespace in the web service uri can be basically anything. I has the exact same purpose as the namespace in c#,c++ or the package in java. You would not like to have a big code base in a single namespace and with web services that is the same.
The reason why it is often the url of the website is because the url of the website has to be unique by definition. And what is unique makes a good name space.