Getting Rid of TempUri in WCF


Everyone of has seen it; the default namespace TempUri reference
in our otherwise neatly published WSDL, looks like an out of place
not-so-thought-out part of your otherwise ironclad contract. Hence the question
arises, how to get rid of it and put your company’s corresponding namespace in
there.

In the asmx services, it was rather easy to do it; just
modify your webservice attribute.

[WebService(Namespace = "http://tempuri.org/")]

However, in the new uncharted waters of WCF, things are wee
bit more complex than this. Now you’d need to do it in multiple places. The
point to remember is that an endpoint has an associated behavior with it.

The web.config file.

 Service Endpoint
<endpoint address=""                                                                                                                                           binding="basicHttpBinding"
                                                                                                                                contract="Acme.Services.WCFNamespaceSample.IService"
                                                                               bindingNamespace
="http://acme.com/Acme/Services/WCFNamespaceSample/">

Behavior Endpoint
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" bindingNamespace="http://acme.com/Acme/Services/WCFNamespaceSample/"/>

Also, for the general namespace changes, you need to specify
the attribute as follows.

namespace Acme.Services.WCFNamespaceSample
{
                [ServiceBehavior
(Namespace = "Acme.Services.WCFNamespaceSample")]
                public class Service :
IService

And

namespace Acme.Services.WCFNamespaceSample
{
                [ServiceContract(Namespace
= "Acme.Services.WCFNamespaceSample")]
                public interface IService

This should do the magic. Following source code is a good
place to start.

WCFNamespaceSample.zip (4.1 KB)

Share

One thought on “Getting Rid of TempUri in WCF

Comments are closed.