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

4 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