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.

Namespace:  System.Web.Services
Assembly:  System.Web.Services (in System.Web.Services.dll)

public string Namespace { get; set; }

Property Value

Type: System.String
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.


An XML namespace is different from the namespace the class resides in, in terms of the Windows Software Development Kit (SDK). To specify the namespace for the class, see Namespace Keywords (C# Reference) if you writing in 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.

<%@ 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();

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0