Provides properties for creating and accessing a single instance of each XML Web service referenced by the current project.
The My.WebServices object provides an instance of each Web service referenced by the current project. Each instance is instantiated on demand. You can access these Web services through the properties of the My.WebServices object. The name of the property is the same as the name of the Web service that the property accesses. Any class that inherits from SoapHttpClientProtocol is a Web service. For information about adding Web services to a project, see Accessing Application Web Services (Visual Basic).
The My.WebServices object exposes only the Web services associated with the current project. It does not provide access to Web services declared in referenced DLLs. To access a Web service that a DLL provides, you must use the qualified name of the Web service, in the form DllName.WebServiceName. For more information, see Accessing Application Web Services (Visual Basic).
The object and its properties are not available for Web applications.
Each property of the My.WebServices object provides access to an instance of a Web service referenced by the current project. The name of the property is the same as the name of the Web service that the property accesses, and the property type is the same as the Web service's type.
If there is a name collision, the property name for accessing a Web service is RootNamespace_Namespace_ServiceName. For example, consider two Web services named Service1. If one of these services is in the root namespace WindowsApplication1 and in the namespace Namespace1, you would access that service by using My.WebServices.WindowsApplication1_Namespace1_Service1.
When you first access one of the My.WebServices object's properties, it creates a new instance of the Web service and stores it. Subsequent accesses of that property return that instance of the Web service.
You can dispose of a Web service by assigning Nothing to the property for that Web service. The property setter assigns Nothing to the stored value. If you assign any value other than Nothing to the property, the setter throws an ArgumentException exception.
You can test whether a property of the My.WebServices object stores an instance of the Web service by using the Is or IsNot operator. You can use those operators to check if the value of the property is Nothing.
Typically, the Is or IsNot operator has to read the value of the property to perform the comparison. However, if the property currently stores Nothing, the property creates a new instance of the Web service and then returns that instance. However, the Visual Basic compiler treats the properties of the My.WebServices object specially, and allows the Is or IsNot operator to check the status of the property without altering its value.
The following table lists an example of a task involving the My.Forms object.
Call a Web Service asynchronously and handle an event when it completes
This example calls the FahrenheitToCelsius method of the TemperatureConverter XML Web service, and returns the result.
For this example to work, your project must reference a Web service named Converter, and that Web service must expose the ConvertTemperature method. For more information, see Accessing Application Web Services (Visual Basic).
This code does not work in a Web application project.