Udostępnij za pośrednictwem


Web References in Visual Studio

Note

This topic pertains to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation.

To simplify development of XML Web service client applications, Visual Studio provides Web references. Web references differ from traditional references and components; instead of referencing a component or a class library installed on the local computer, a Web reference provides access to a resource that is available using an Internet protocol such as SOAP or HTTP.

In practice, a Web reference is a generated proxy class that locally represents the exposed functionality of an XML Web service. The proxy class defines methods that represent the actual methods exposed by an XML Web service. When your application creates an instance of the proxy class, your application can call the XML Web service methods as if the XML Web service were a locally available component. For instructions on creating a Web reference, see How to: Add and Remove Web References.

Note

To make XML Web services outside a firewall available to the Web browser, when creating the Web reference in Visual Studio, you must explicitly specify the address and port of your network's proxy server.

The programming language of a generated proxy class will be the same as the programming language of the Web service that the proxy class represents. If you create the proxy class independently of Visual Studio (for example, by using a .NET Framework tool), the programming language depends on which tool you use. For example, if you use WSDL.exe, you specify the programming language on the command line as either C# or Visual Basic. If you use SProxy.exe, the programming language is Visual C++. For more information, see Web Services Description Language Tool (Wsdl.exe).

At design time, the proxy class enables you to use statement completion for the XML Web service methods. At run time, a call to a method of the proxy object is processed and encoded as a SOAP request message. If the XML Web service does not support SOAP, the proxy class uses HTTP GET and POST. The message is then sent to the target Web Service for processing. If the service description defines a response message, the proxy object processes this message and returns a response to your application.

Managing Web References

You can rename or modify Web references or update them if the referenced Web service has changed. For details, see How to: Rename a Project Web Reference and How to: Update a Project Web Reference.

URL Behavior Property

Each Web reference in your project interacts with a proxy class that is used to access the Web service. You can use the Web reference URL property to specify the URL to the XML Web service. In ASP.NET 1.1, a Web reference can use either a static URL or a dynamic URL. In ASP.NET 2.0 and later, a Web reference obtains the URL dynamically. For more information, see Locating Web Services.

When you create a Web reference in Visual Studio using the Add Web Reference dialog box, this property is set by default to the URL of the XML Web service you select, which is a static 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 of the Web reference to dynamic, the application obtains the URL at run time from the appSettings element of your application's configuration file.

See Also

Tasks

How to: Add and Remove Web References

How to: Rename a Project Web Reference

How to: Update a Project Web Reference

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

Other Resources

XML Web Service Discovery

Creating an XML Web Service Proxy

Web Services Description Language Tool (Wsdl.exe)