Saturday, June 06, 2009

Removing Namespace From WSDL

If you need to remove the references to “” from the WSDL of your web service, the following are the steps to do so:

  • Add [ServiceContract(Namespace = "MyContractNamespace")] to the Interface definition. Example:
[ServiceContract(Namespace = "MyContractNamespace")]
   public interface ITest
       string Echo(string str);
  • Add [ServiceBehavior(Namespace = "MyServiceNamespace")] to the service implementation. Example:

[ServiceBehavior(Namespace = "MyServiceNamespace")]
   public class Service : ITest
       public string Echo(string str)
           return str;

  • Add bindingNamespace=”MyServiceNamespace” to each endpoint definition in the Web.config file. Example:

<endpoint contract="ITest" binding="wsHttpBinding" address="" bindingNamespace="MyServiceNamespace">

The above three points will make all the references to “” disappear from the WSDL contract of the service (i.e. http://localhost/MyService.svc?wsdl).

References: eliminating in wsdl (link), wsdl:import namespace (link)

1 comment:

Chuck said...

Helpful post. In the above for the binding example, the attribute name should be bindingNamespace (case sensitive).