WebServiceAttribute.Namespace 属性
定义
获取或设置用于 XML Web services 的默认 XML 命名空间。Gets or sets the default XML namespace to use for the XML Web service.
public:
property System::String ^ Namespace { System::String ^ get(); void set(System::String ^ value); };
public string Namespace { get; set; }
member this.Namespace : string with get, set
Public Property Namespace As String
属性值
用于 XML Web services 的默认 XML 命名空间。The default XML namespace to use for the XML Web service. 默认值在 DefaultNamespace 属性中指定。The default is specified in the DefaultNamespace property.
示例
下面的示例将设置 Namespace 为 http://www.contoso.com ,并 Action 通过将添加 SoapDocumentMethodAttribute 到 XML Web service 方法来重写属性的命名空间 Time 。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();
}
}
<%@ WebService Language="VB" class= "ServerVariables"%>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Description := "Server Variables", _
Namespace := "http://www.contoso.com/")> _
Public Class ServerVariables
Inherits WebService
<SoapDocumentMethod(Action := "http://www.contoso.com/Time"), _
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
注解
XML 命名空间提供了一种在 XML 文档中创建名称的方法,该文档由 (URI) 的统一资源标识符标识。XML namespaces offer a way to create names in an XML document that are identified by a Uniform Resource Identifier (URI). 通过使用 XML 命名空间,可以唯一标识 XML 文档中的元素或属性。By using XML namespaces you can uniquely identify elements or attributes in a XML document. XML Web service 的服务说明是在 XML 中定义的,尤其是在 Web Services 描述语言 (WSDL) 中定义的。The service description for a XML Web service is defined in XML, specifically in Web Services Description Language (WSDL).
在 XML Web service 的服务说明中, Namespace 用作直接与 XML Web service 相关的 XML 元素的默认命名空间。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. 例如,XML Web service 及其 XML Web service 方法的名称与属性中指定的命名空间有关 Namespace 。For example, the name of the XML Web service and its XML Web service methods pertain to the namespace specified in the Namespace property. 特定于 WSDL 的元素属于 http://schemas.xmlsoap.org/wsdl/ 命名空间。Elements that are specific to WSDL pertain to the http://schemas.xmlsoap.org/wsdl/ namespace.
对于使用 SOAP 调用 XML Web service 的 XML Web service 客户端,可以选择性地添加 SoapDocumentMethodAttribute 或 SoapRpcMethodAttribute 以调用 XML Web service 方法。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. 如果客户端调用使用 ASP.NET 创建的 XML Web service,则 RequestNamespace ResponseNamespace 默认情况下,和 Action 属性均派生自 Namespace 属性。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. 例如,给定 XML Web service 方法名称,属性为 Time ,则 Namespace http://www.contoso.com/ Action 默认情况下该属性为 http://www.contoso.com/Time 。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. 若要更改 XML Web service 方法的、和的默认设置, RequestNamespace ResponseNamespace 可以向 Action XML Web service 方法中添加 SoapDocumentMethodAttribute 。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.
备注
XML 命名空间不同于类所驻留的命名空间,Windows SDK。An XML namespace is different from the namespace the class resides in, in terms of the Windows SDK. 若要指定类的命名空间,请参阅命名空间关键字(如果你用 c # 编写)。To specify the namespace for the class, see Namespace Keywords if you writing in C#.