WebMethodAttribute.MessageName 屬性

定義

在 XML Web Service 方法中傳遞並傳回的資料中,XML Web Service 方法所使用的名稱。

public:
 property System::String ^ MessageName { System::String ^ get(); void set(System::String ^ value); };
public string MessageName { get; set; }
member this.MessageName : string with get, set
Public Property MessageName As String

屬性值

String

在對 XML Web Service 方法來回傳遞的資料中,XML Web Service 方法所使用的名稱。 預設值為 XML Web Service 方法的名稱。

範例

在下列範例中, MessageName 是用來厘清這兩 Add 種方法。

<%@ WebService Language="C#" Class="Calculator" %>
 
 using System;
 using System.Web.Services;
 
 public class Calculator : WebService {
    // The MessageName property defaults to Add for this XML Web service method.
    [WebMethod]
    public int Add(int i, int j) {
       return i + j;
    }   
    [WebMethod(MessageName="Add2")]
    public int Add(int i, int j, int k) {
       return i + j + k;
    }   
 }
<%@ WebService Language="VB" Class="Calculator" %>

Imports System
Imports System.Web.Services

Public Class Calculator
    Inherits WebService
    
    ' The MessageName property defaults to Add for this XML Web service method.
    <WebMethod()> _
    Overloads Public Function Add(i As Integer, j As Integer) As Integer
        
        Return i + j
    End Function
    
    <WebMethod(MessageName := "Add2")> _
    Overloads Public Function Add(i As Integer, j As Integer, k As Integer) As Integer
        
        Return i + j + k
    End Function    
End Class

備註

屬性 MessageName 可以用來別名方法或屬性名稱。 屬性最常見的用法 MessageName 是唯一識別多型方法。 根據預設, MessageName 會設定為 XML Web 服務方法的名稱。 因此,如果 XML Web 服務包含兩個以上具有相同名稱的 XML Web 服務方法,您可以將 設定 MessageName 為 XML Web 服務內唯一的名稱來唯一識別個別的 XML Web 服務方法,而不需在程式碼中變更實際方法名稱的名稱。

當資料傳遞至 XML Web 服務時,它會在要求中傳送,並在傳回時在回應中傳送。 在要求和回應中,用於 XML Web 服務方法的名稱是其 MessageName 屬性。

與 XML Web 服務方法相關聯的訊息名稱在 XML Web 服務內必須是唯一的。

如果在用戶端呼叫原始方法之後新增具有相同名稱但不同參數的新 XML Web 服務方法,則應該為新方法指定不同的訊息名稱,但原始訊息名稱應該保留為 ,以確保與現有的用戶端相容。

適用於

另請參閱