locked
Web Service Namespace: Why to change it from tempuri.org?

    Question

  • I'm developing Web App which has some bussiness logic in web services.

    By default Visual Studio creates web service class with Namespace tempuri.org:

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

      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

      public class MyService : System.Web.Services.WebService { ...

     

    During the development we leave the namespace as it is - and it works great. Soon we're goring to release the app and I'm warring about the namespace. Should we change it to the url of the web app or whatever? Could you please explain when namespace is used and if there's any sense in changing it from tempuri.org?

    Friday, June 15, 2007 11:33 AM

Answers

  • Following is the guidance and reason provided in help page of your web service.

     

    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
     
    Friday, June 15, 2007 6:58 PM
    Moderator

All replies

  • Following is the guidance and reason provided in help page of your web service.

     

    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
     
    Friday, June 15, 2007 6:58 PM
    Moderator
  • I am writting a webservice that will be deployed a several customer sites each with their own unique and  different domain name.  How can I dynamicall, programmatically or via a config file alter the namespace property?
    Wednesday, July 11, 2007 10:00 PM
  • The namespace property is not something that should be changed. In particular, even though it is in the form of a URL (or URI), it does not need to refer to a location on the Internet. Therefore, it does not need to change when the Internet location changes.

    Friday, July 13, 2007 7:58 PM
    Moderator
  • I have been getting a (500) Internal Server Error from one or two users and while trying to track it down I noticed that I hadn't changed the tempuri.org in the webservice.  Do you know if a conflict with the namespace could cause an error like this?  What kind of an error could someone expect if they did NOT change the default tempuri.org namespace and a conflict occurred? 

     

    I would appreciate any help.

    Wednesday, October 31, 2007 7:55 PM
  • Internal Server Error (500) means that the service threw an exception that was not caught. The exception could be anything at all, except that it is almost certainly unrelated to the namespace.

     

    Check the Windows Event Log on the web server hosting the service. See if there are any errors or warnings in the Application log at about the time you received the 500 error.

     

    Wednesday, October 31, 2007 10:23 PM
    Moderator
  • Thanks for your help.  I will look to the logs for more help with the 500 error.  But I'm still curious, now that I've noticed that I published my web service with the default tempuri.org what kind of errors or problems could I encounter because of that?  I read everywhere that you should change it before going to production, and I forgot.  Since I have customers who have a PC application that calls my webservice with that default namespace, it appears that I can't just change it now without first getting them a version of the PC application that references the web service with the new namespace.  (Which will involve jumping through a few hoops because the web service is the method we used to update the PC application to newer versions)  So I guess I'm doing this backwards...usually people post the symptom of the problem and ask for a diagnoses.  I've got the problem, but haven't had any symptoms yet.  I'm just curious what they will be if/when I get them.  Any ideas?

     

    Thanks for your time.

    Thursday, November 01, 2007 1:31 PM
  • Hi,

     

    The namespace is used to fully qualify your service (just like a C# namespace), so changing the tempuri.org namespace is just a best practice, but it won't break anything if it is working fine now.

    In a SOA scenario it is sometimes very important to use correct and defined namespaces as an ESB or an integration bus can use it to manage WS addressing or message routing.

    If this is not your case (you access the WS directly from the client application) you won't have any problem... you're just not following a best practice but it will work with no problem.

     

    Regards,

    Rodrigo

    Thursday, November 01, 2007 1:41 PM
  • The issue is easier to see if you consider an environment (maybe SOA) where multiple web services are being used, possibly one service using another, or using XML coming from elsewhere. Let's say that your service has a "Group" type. The qualified name for that type would then be {http://tempuri.org/}:Group. It's easy to imagine another webservice also having a Group type, possibly one that means something else entirely. If they also leave theirs under http://tempuri.org, then you've got a naming conflict.

     

    This is obviously not a problem for you today. However, web services enable mixing and matching, and the problem may be there tomorrow.

     

    Besides, it looks very unprofessional. I mean, Microsoft probably left tempuri.org as the default for the benefit of developers who were just playing around, creating web services that nobody will ever use.

    Thursday, November 01, 2007 2:36 PM
    Moderator
  • Thanks Rodrigo and John Saunders for your help.

     

    Thursday, November 01, 2007 5:38 PM
  •  I received the exact message posted by Vipul Modi while doing the walkthrough
    "Process for creating a distributed application."

    My question is, "Where (exactly) do I put the recommended C# code?"

    Since the "[WebService..." line comes just before "public class MyWebService",
    I tried putting the line in AuthorsService.asmx.cs as follows:


    namespace AuthorsWebService
    {
        /// <summary>
        /// Summary description for Service1.
        /// </summary>
        ///

        [WebService(Namespace="http://www.mydomain.com")]             <======== HERE
        public class AuthorsService : System.Web.Services.WebService
        {
            public AuthorsService()
            {
                //CODEGEN: This call is required by the ASP.NET Web Services Designer
                InitializeComponent();
            }
    ...

    but, when I run and click the "Load" button, I get a pop-up message (error):

    "An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in system.web.services.dll

    "Additional information: Server did not recognize the value of HTTP Header SOAPAction: http://tempuri.org/GetAuthors."


    So, obviously, I've put it in the wrong place.
    Where should I put the C# code?




    • Edited by fuzoid Wednesday, December 03, 2008 8:34 PM previous edit didn't seem to work
    Wednesday, December 03, 2008 8:22 PM