This documentation is archived and is not being maintained.

WebServiceAttribute.Namespace Property

Gets or sets the default XML namespace to use for the XML Web service.

[Visual Basic]
Public Property Namespace As String
public string Namespace {get; set;}
public: __property String* get_Namespace();
public: __property void set_Namespace(String*);
public function get Namespace() : String;
public function set Namespace(String);

Property Value

The default XML namespace to use for the XML Web service. The default is specified in the DefaultNamespace property.


XML namespaces offer a way to create names in an XML document that are identified by a Uniform Resource Identifier (URI). By using XML namespaces you can uniquely identify elements or attributes in a XML document. The service description for a XML Web service is defined in XML, specifically in Web Services Description Language (WSDL).

Within the Service Description for an XML Web service, Namespace is used as the default namespace for XML elements directly pertaining to the XML Web service. For example, the name of the XML Web service and its XML Web service methods pertain to the namespace specified in the Namespace property. Elements that are specific to WSDL pertain to the namespace.

For XML Web service clients using SOAP to call an XML Web service, you can optionally add the SoapDocumentMethodAttribute or SoapRpcMethodAttribute to call an XML Web service method. If the client is calling an XML Web service created using ASP.NET, the RequestNamespace, ResponseNamespace and Action properties are all derived from the Namespace property by default. For instance, given an XML Web service method name of Time and a Namespace property of, the Action property is by default. To change the default settings for RequestNamespace, ResponseNamespace, and Action for an XML Web service method, you can add a SoapDocumentMethodAttribute to the XML Web service method.

Note   An XML namespace is different from the namespace the class resides in, in terms of the Microsoft .NET Framework SDK. To specify the namespace for the class, see 9. Namespaces if you writing in C#.


[Visual Basic, C#] The following example sets Namespace to and overrides that namespace for the Action property by adding a SoapDocumentMethodAttribute to the Time XML Web service method.

[Visual Basic] 
<%@ WebService Language="VB" class= "ServerVariables"%>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Description := "Server Variables", _
    Namespace := "")> _
Public Class ServerVariables
    Inherits WebService

    <SoapDocumentMethod(Action := ""), _
        WebMethod(Description := "Returns the time as stored on the Server", _
        EnableSession := False)> _
    Public Function Time() As String
        Return Context.Timestamp.TimeOfDay.ToString()
    End Function
End Class

<%@ WebService Language="C#" class= "ServerVariables"%>
 using System;
 using System.Web.Services;
 using System.Web.Services.Protocols;
 [ WebService(Description="Server Variables",
 public class ServerVariables: WebService {
    [ SoapDocumentMethod(Action="")]
    [ WebMethod(Description="Returns the time as stored on the Server",EnableSession=false)]
    public string Time() {
       return Context.Timestamp.TimeOfDay.ToString();

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

WebServiceAttribute Class | WebServiceAttribute Members | System.Web.Services Namespace | DefaultNamespace | SoapDocumentMethodAttribute | RequestNamespace | ResponseNamespace | Action | SoapRpcMethodAttribute