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)






6/13/2008 11:18:28 AM (Pacific Standard Time, UTC-08:00) #    Comments [1]  |  Trackback
Tracked by:
"Interesting Finds: June 14, 2008" (Jason Haley) [Trackback]

 

All content © 2008, Adnan Masood
About the Author
On this page
Calendar
<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Archives
Sitemap
Blogroll OPML
microsoft
Blogroll
Disclaimer

Powered by: newtelligence dasBlog 1.8.5223.2

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts