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 http://schemas.xmlsoap.org/wsdl/ 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 http://www.contoso.com/, the Action property is http://www.contoso.com/Time 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.

NoteNote

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 http://www.contoso.com 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",
 Namespace="http://www.contoso.com/")]
 public class ServerVariables: WebService {
    [ SoapDocumentMethod(Action="http://www.contoso.com/Time")]
    [ WebMethod(Description="Returns the time as stored on the Server",EnableSession=false)]
    public string Time() {
       return Context.Timestamp.TimeOfDay.ToString();
    }
 }
 

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft