Skip to main content

WebMethod (Method Keyword)

Specifies whether this method is a web method. Applies only in a class that is defined as a web service or web client.

Usage

To specify that this method is a web method, use the following syntax:

Method name(formal_spec) As returnclass [ WebMethod ] 
{    //implementation }

Otherwise, omit this keyword or place the word Not immediately before the keyword.

Details

This keyword specifies that this method is available as a web method and can be invoked via the SOAP protocol.

Important:

In most cases, web methods should be instance methods, rather than class methods. For details and for other requirements for a web method, see Creating Web Services and Web Clients.

Default

If you omit this keyword, the method is not available as a web method.

Generated Class

When you add this keyword to a method and compile the class, the class compiler generates an additional class: Package.OriginalClass.MethodName, where Package.OriginalClass is the class that contains the web method, and MethodName is the name of web method.

For example, suppose that you start with the class ROBJDemo.DocLiteralWS and you add a method to it named Add. When you add the WebMethod keyword to that method and compile, the class compiler generates the class ROBJDemo.DocLiteralWS.Add.

Do not modify or directly use this generated class; it is intended only for internal use.

Relationship to WSDL

For a web service, this keyword also affects the generated WSDL, which now contains the additional elements needed to represent this web method.

See Also

FeedbackOpens in a new tab