I’ve been working with WCF services a lot lately and I always specify namespaces for my service- and data-contracts. But I noticed that – by default – the WSDL of such a WCF service is generated in two parts:

  • a part that resides in the namespace "http://tempuri.org/",
  • a part that resides in the namespace I specified for the service.

The first WSDL contains an import of the second one. This also results in two separate .WSDL files when you download the meta-data (I leave any generated XML Schemas containing the data-contracts out of it in this post).

Although this works fine, I wondered whether or not it is possible to combine these WSDL files in to one file that uses the namespace I specified for my service, and get rid of this ugly "tempuri" namespace. And guess what, this is easy!

Here’s an example of a service I will use to demonstrate how to do this:

[ServiceContract(Namespace = "urn:wcfsamples:mywcfservice")] 
public interface IMyWcfService 
string GetData(int value); 

// implementation of the service 
public class MyWcfServiceImpl : IMyWcfService 
public string GetData(int value) 
return string.Format("You entered: {0}", value); 

This must look familiar. Now, to make sure the WSDL that is generated for the service (once you created a host) consists of only one part that resides in the specified namespace, you must take the following steps:

  1. Add a ServiceBehavior attribute to the implementation-class, and specify the service’s namespace.
  2. Add the bindingNamespace attribute to all (non meta-data exchange) endpoints you configured for the service.

Example of step 1:


Example of step 2:


Finally, here’s a fragment of the WSDL that is generated for the service:

<xml version="1.0" encoding="utf-8" ?> 
<wsdl:definitions name="MyWcfServiceImpl" targetNamespace="urn:wcfsamples:mywcfservice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://

That’s it. When you now download the meta-data for this service, you get only one .WSDL file. Exactly what I wanted.

I hope you find this information useful. And remember: let’s keep our WSDL tidy!

This entry was posted in Microsoft Development by Edwin van Wijk. Bookmark the permalink.

3 thoughts on “WCF: namespaces in WSDL

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>