This documentation is archived and is not being maintained.

WebMethodAttribute.MessageName Property

The name used for the XML Web service method in the data passed to and returned from an XML Web service method.

[Visual Basic]
Public Property MessageName As String
[C#]
public string MessageName {get; set;}
[C++]
public: __property String* get_MessageName();
public: __property void set_MessageName(String*);
[JScript]
public function get MessageName() : String;
public function set MessageName(String);

Property Value

The name used for the XML Web service method in the data passed to and from an XML Web service method. The default is the name of the XML Web service method.

Remarks

The MessageName property can be used to alias method or property names. The most common use of the MessageName property will be to uniquely identify polymorphic methods. By default, MessageName is set to the name of the XML Web service method. Therefore, if an XML Web service contains two or more XML Web service methods with the same name, you can uniquely identify the individual XML Web service methods by setting the MessageName to a name unique within the XML Web service, without changing the name of the actual method name in code.

When data is passed to an XML Web service it is sent in a request and when it is returned it is sent in a response. Within the request and response, the name used for the XML Web service method is its MessageName property.

The message name associated with an XML Web service method must be unique within the XML Web service.

If a new XML Web serivce method with the same name but different parameters is added after clients are calling the original method, a different message name should be specified for the new method but the original message name should be left as is to ensure compatability with existing clients.

Example

[Visual Basic, C#] In the example below, MessageName is used to disambiguate the two Add methods.

[Visual Basic] 
<%@ 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


[C#] 
<%@ 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;
    }   
 }

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

WebMethodAttribute Class | WebMethodAttribute Members | System.Web.Services Namespace | WebMethodAttribute

Show: