Monday, January 12, 2009

How to get rid of http://tempuri.org/ 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 http://tempuri.org/ for this purpose. While this suitable for XML Web Services under development, published services should use a unique, permanent namespace." (http://tempuri.org)

By default WCF maps all service operations to the targetnamespace http://tempuri.org/ .
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 http://tempuri.org namespace for their operations, you can't uniquely indentify them.

To get rid of http://tempuri.org/ in your WSDL in WCF do the following:

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

[ServiceContract(Namespace = "http://myservice.com")]

public interface IMyService

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

[ServiceBehavior(Namespace = "http://myservice.com")]

class MyService : IMyService

3.) In all your bindings set the bindingNamespace property

<endpoint binding="basicHttpBinding" bindingNamespace="http://myservice.com"....

7 comments:

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...

bindingNamespace="http://myservice.com"

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.