Updated: July 20, 2015
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
Provides properties for creating and accessing a single instance of each XML Web service referenced by the current project.
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.
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.
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
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
IsNot operator. You can use those operators to check if the value of the property is
This example calls the
FahrenheitToCelsius method of the
TemperatureConverter XML Web service, and returns the result.
Function ConvertFromFahrenheitToCelsius( ByVal dFahrenheit As Double) As Double Return My.WebServices.TemperatureConverter.FahrenheitToCelsius(dFahrenheit) End Function
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.
This code does not work in a Web application project.
|Windows Control Library||Yes|
|Web Control Library||Yes|