Why change the Web Service Namespace from tempuri.org

Posted on November 4, 2011

0


When you create a Web Service the default Namespace is

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

I was wondering firstly should I change it and secondly what should I change it to.  The default Namespace doesn’t really give you much of an indication or example.

The short answer is all Web Services need a unique namespace to distinguish it from other Web Services on the web and the best way to do this is put the company you work for in it e.g. for me

http://metaphorix.com

Whilst you are developing the Web Service is fine to leave as tempuri.org but don’t forget to change this before you make it public.

I can’t be the only person to wonder about this because Microsoft has a support page dedicated to the question

No recommendation is made to change the http://tempuri.org/ namespace in Visual C++ .NET Managed C++ Web Service applications

Although it’s not really the question I am asking it does provide the answer, there are two useful parts in the article

 

You can change the default namespace by using the Namespace property of the WebService attribute. TheWebService attribute is an attribute that is applied to the class that contains the XML Web service methods. The following example sets the namespace to “http://microsoft.com/webservices/”:

  [WebService(Namespace="http://microsoft.com/webservices/")]
	public __gc 
        class MyWebServiceClass : public System::Web::Services::WebService
    {
        // Implementation     
    };

Identify your XML Web service with a namespace that you control. For example, you can use the Internet domain name of your company as part of the namespace. Many XML Web service namespaces look similar to URLs, however, namespaces do not have to point to actual resources on the Web. (XML Web service namespaces are URIs.)

 

Each XML Web service must have a unique namespace for client applications to distinguish the Web service from other services on the Web. For XML Web services that are under development, “http://tempuri.org/” is available. However, use a more permanent namespace for published XML Web services. For additional information about XML namespaces, see the following World Wide Web Consortium (W3C) Web site:

 

There are also some good forum discussion on the topic.

The two forums discussion I found useful can be read here and here

The first one probably provides the best answer, written by Vipul Modi – MSFT

This web service is using http://tempuri.org/ as its default namespace.

Recommendation: Change the default namespace before the XML Web service is made public.

Each XML Web service needs a unique namespace in order for client applications to distinguish it from other services on the Web. http://tempuri.org/ is available for XML Web services that are under development, but published XML Web services should use a more permanent namespace.

Your XML Web service should be identified by a namespace that you control. For example, you can use your company’s Internet domain name as part of the namespace. Although many XML Web service namespaces look like URLs, they need not point to actual resources on the Web. (XML Web service namespaces are URIs.)

For XML Web services creating using ASP.NET, the default namespace can be changed using the WebService attribute’s Namespace property. The WebService attribute is an attribute applied to the class that contains the XML Web service methods. Below is a code example that sets the namespace to “http://microsoft.com/webservices/”:

C#

[WebService(Namespace="http://microsoft.com/webservices/")]
public class MyWebService {
    // implementation
}
- Vipul Modi - MSFT
About these ads
Posted in: .NET