WCF Service Namespaces

Since I seem to forget this on a regular basis, I wanted to leave a note
to myself for future reference. I also want to post a link to the Tech
Talk
blog where I found most of this information.

By default, WCF assigns the namespace “http://tempuri.org/“ to all web
service operations. (For more information on tempuri.org, see the W3C
Note on WSDL
.) Typically you will want to assign your own namespace
to uniquely identify any web services you have deployed. Since WCF has a
(seemingly) infinite number of configuration options, there are no fewer
than three places you need to set the namespace to keep WCF from using
the default tempuri.org.

The first is on the ServiceContract attribute. Set the namespace in
the attribute constructor.

1
[ServiceContract(Namespace = @"http://someservice.example.com/")]

public interface ISomeService

The second place it needs to be set is on the ServiceBehavior
attribute. Again, set the namespace in the attribute constructor.

1
2
[ServiceBehavior(Namespace = @"http://someservice.example.com/")]
public class SomeService : ISomeService

The third and final place it needs to be set is the bindingNamespace
attribute on the endpoint element in the App.config file.

1
2
3
<endpoint bindingNamespace="http://someservice.example.com/"...>
...
</endpoint>