This documentation is archived and is not being maintained.

How to: Create an XML Web Service Method 

When you create an XML Web service in managed code, you indicate the methods that are available through that XML Web service by placing the WebMethod attribute before the method declaration of a Public method. Private methods cannot serve as the entry point for an XML Web service although they can be in the same class and the XML Web service code can call them. The WebMethod attribute must be applied to each public method that is available as part of the XML Web service. For more information, see How to: Use the WebMethod Attribute.

The procedures below assume that you are working with public methods of a class that is the implementation of an XML Web service. For more information, see Code Model for XML Web Services in Managed Code.

To create an XML Web service method

  1. Double-click your .vb or .cs file (for example, Service1.vb or Service1.cs) in Solution Explorer to open the code editor.

  2. Add a public method to the class specified in the Class property of the .asmx file's WebService processing directive as shown below:

    Public Class Service1
        Inherits System.Web.Services.WebService
        <System.Web.Services.WebMethod()> _
        Public Function ConvertTemperature(ByVal dFahrenheit As Double) _
                                           As Double 
            ConvertTemperature = ((dFahrenheit - 32) * 5) / 9 
        End Function 
    End Class
    
    

    public class Service1 : System.Web.Services.WebService
    { 
        [System.Web.Services.WebMethod()]
        public double ConvertTemperature(double dFahrenheit)
        {
           return ((dFahrenheit - 32) * 5) / 9;
        }
    }
    

    Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the XML Web service. For more information, see Code Model for XML Web Services in Managed Code.

See Also

Show: