Wednesday, April 17, 2013

WCF : Simple Steps to remove tempuri namespace from your WSDL


If we create a WCF web service with default settings then we see the http://tempuri.org/  namespace in WSDL as shown below

Screen Shot 1: Default Configuration Setting of WCF Service



Screen Shot 2: Showing the http://tempuri.org/ namespace in WSDL with Default Configuration Setting



If you want to replace the http://tempuri.org/ with your company’s URI then you need to follow these simple steps. Here I tried to write the simple steps with the example of simple WCF service with the following structure



And the following steps are required to  replace the http://tempuri.org/ with your company’s URI

Step 1: Assign the Namespace property in your service contract attribute as shown in highlighted font below

[ServiceContract(Namespace = "http://localhost/Services/MyRestfulService/2013/04/")]
public interface IPost
    {

        [OperationContract]
        string GetData(string value);
   
    }
     


Step 2: Assign the Namespace property in your Service behavior attribute as shown in highlighted font below
[ServiceBehavior(Namespace = "http://localhost/Services/MyRestfulService/2013/04/")]
    public class MyPosts : IPost
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
      
    }


Step 3:  Create a service Endpoint in web.config and assign the bindingNamespace with namespace as you configured in Service behavior and service contract attributes as shown in highlighted font below.
<service name="MyRestfulService.MyPosts">
  <endpoint address="Api" binding="webHttpBinding" contract="MyRestfulService.IPost"
       behaviorConfiguration="restfulBehaviour
       bindingNamespace="http://localhost/Services/MyRestfulService/2013/04/">
  </endpoint>
</service>


Here in this example I used webHttpBinding but you can follow these steps with any type of binging.
After doing all these settings the WSDL will look like the following:



There is not tempuri in WSDL and instead of http://tempuri.org/ your http://localhost/Services/MyRestfulService/2013/04/ namespace will display.

The most important thing you need to consider is at every point you need to put same URI address.

Post a Comment