Export (0) Print
Expand All

Locating XML Web Services

Sometimes you may be both the provider and consumer of an XML Web service. In this case, you probably know the location and function of the XML Web service. At other times, you may be accessing an XML Web service provided by someone else. When this occurs, you may not even know if an XML Web service that suits your purposes in fact exists.

To simplify the coding model, applications written in managed code use a Web reference to locally represent each XML Web service. You add a Web reference to your project by using the Add Web Reference dialog box. This dialog box makes it possible for you to browse your local server, the Microsoft UDDI Directory, and the Internet at large. XML Web service providers publicize their XML Web services in XML Web services directories, which is where XML Web service consumers search of XML Web services to consume. For more information, see XML Web Services Directories.

The Add Web Reference dialog box uses the process of XML Web service discovery to locate eligible XML Web services on Web sites to which you navigate in the dialog box. For a given address, it will interrogate the Web site using an algorithm designed to locate XML Web service discovery (DISCO) documents and ultimately, XML Web service description documents that adhere to the grammar of the Web Services Description Language (WSDL). For more information, see XML Web Service Discovery and XML Web Service Description.

After you have located an XML Web service for your application to access by using the Add Web Reference dialog box, clicking the Add Reference button will instruct Visual Studio to download the service description to the local machine and then generate a proxy class for the chosen XML Web service. The proxy class will contain methods for calling each exposed XML Web service method both synchronously and asynchronously. This class is contained in the local .wsdl file's code-behind file. For more information, see Web References and Add Web Reference Dialog Box.

You can use the Web Reference URL property to specify the URL to the XML Web service. The Add Web Reference sets this property by default to the URL of the XML Web service you select, which is a static URL. A Web reference can use either a static URL or a dynamic URL.

If you leave the URL Behavior set to the default value of static, the proxy class sets the URL property using a hard-coded URL when you create an instance of the class.

If you set the URL Behavior property of the Web reference to dynamic, the application obtains the URL at run time from the <appSettings> Element of your application's configuration file. When you specify a dynamic URL after adding a Web reference, Visual Studio updates the proxy class to obtain the URL from the configuration file.

<appSettings>
   <add key="myApplication.myServer.Service1"
        value="http://myServer/myXmlWebService/Service1.asmx"/>
</appSettings>

When you create an instance of a proxy object, you can also set the URL property of the object in your application.

Regardless of which URL the proxy uses, it must be for an XML Web service that adheres to a WSDL that matches the one used when adding the Web reference. For more information, see Managing Project Web References.

Alternatively, you can generate a proxy class using a tool (XML Web services Description Language Tool) that is similar to the one used by Visual Studio to create a proxy class when adding a Web reference. This is necessary when you are unable to access the XML Web service from the machine on which Visual Studio is installed, such as when the XML Web service is located on a network that will not be accessible to the client until run time. You then manually add the file that the tool generated to your application project. For more information, see Generating an XML Web Service Proxy.

See Also

Accessing XML Web Services in Managed Code | Managing Project Web References | Building XML Web Service Clients | Web Services Description Language (WSDL) Explained

Show:
© 2014 Microsoft