WebServiceAttribute.Namespace 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定要使用於 XML Web Service 的預設 XML 命名空間。
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 Service 的預設 XML 命名空間。 在 DefaultNamespace 屬性中指定預設。
下列範例會將 新增 至 XML Web 服務方法,來設定 Namespacehttp://www.contoso.com
和 覆寫 屬性的 Time
該命名空間 Action 。 SoapDocumentMethodAttribute
<%@ 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 命名空間來唯一識別 XML 檔中的元素或屬性。 XML Web 服務的服務描述是在 XML 中定義,特別是 Web 服務描述語言 (WSDL) 。
在 XML Web 服務的 [服務描述] 內, Namespace 會作為與 XML Web 服務直接相關的 XML 元素的預設命名空間。 例如,XML Web 服務的名稱及其 XML Web 服務方法與 屬性中指定的 Namespace
命名空間有關。 WSDL 專屬於 命名空間的專案 http://schemas.xmlsoap.org/wsdl/ 。
對於使用 SOAP 呼叫 XML Web 服務的 XML Web 服務用戶端,您可以選擇性地新增 SoapDocumentMethodAttribute 或 SoapRpcMethodAttribute 來呼叫 XML Web 服務方法。 如果用戶端呼叫使用 ASP.NET 建立的 XML Web 服務, RequestNamespace 則 和 ResponseNamespaceAction 屬性預設都是衍生自 Namespace 屬性。 例如,假設 的 XML Web 服務方法名稱和 Time
的 屬性,則 Action
屬性預設為 http://www.contoso.com/Time
。 http://www.contoso.com/
Namespace
若要變更 、 ResponseNamespace
和 Action
XML Web 服務方法的預設設定 RequestNamespace
,您可以將 新增 SoapDocumentMethodAttribute 至 XML Web 服務方法。
注意
XML 命名空間與 類別所在的命名空間不同,就 Windows SDK 而言。 若要指定 類別的命名空間,如果您在 C# 中撰寫,請參閱 Namespace Keywords 。
產品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |