WebServiceAttribute.Name 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 XML 網路服務的名稱。
public:
property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String
屬性值
XML 網路服務的名稱。 預設值是實作 XML Web 服務的類別名稱。
範例
以下範例將 XML Web 服務 集合 Name 為 MyName。
<%@ WebService Language="C#" class= "ServerVariables"%>
using System.Web.Services;
[ WebService(Description="Server Variables",
Namespace="http://www.microsoft.com/",
Name="MyName")]
public class ServerVariables: WebService {
[ 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.Web.Services
<WebService(Description := "Server Variables", _
Namespace := "http://www.microsoft.com/", _
Name := "MyName")> _
Public Class ServerVariables
Inherits WebService
<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 Web 服務的 URL 並提供查詢字串 ? 時,服務描述會產生WSDL。 在服務描述中,屬性 Name 標示XML限定名稱中XML的本地部分。 此 Name 屬性也用於服務說明頁面中顯示 XML Web 服務的名稱。 當潛在使用者未指定 XML Web 服務方法名稱及其參數,直接瀏覽至 XML Web 服務的 .asmx 頁面時,會顯示服務說明頁面。
XML 限定名稱用於區分同名元素與 XML 文件的歧義。 XML 限定名稱由以下兩個部分組成,中間以冒號分隔:命名空間或與命名空間相關的前綴,以及本地部分。 命名空間由一個 URI 參考組成,對於服務描述而言,是該 Namespace 屬性的值。 一般而言,前綴(作為 URI 的別名)會與命名空間相關聯,因此所有後續使用 XML 限定名稱的名稱都可以使用縮短後的前綴。 局部部分是以字母或底線開頭且無空格的字串。 因此,服務描述中用來識別 XML 網路服務的 XML 限定名稱格式如下:
欲了解更多關於 XML 限定名稱的資訊,請參閱 XML 1.0 中的命名空間。