You need to create the Proxy class when you want to consume a web service as described in the article How to consume a web service in ASP.NET. In this case you can use the wsdl.exe command-line tool which takes a web service and generates the source code of the proxy class in C# or in VB.NET. 

You can find the tool in the .NET Framework directory, which is in a path similar to c:\Program Files\Microsoft Visual Studio 2005\SDK\v2.0\Bin. In ASP.NET, you can request a WSDL document by specifying the URL of the web service plus the ?WSDL parameter.

The minimum syntax to generate the class is the following:

wsdl https://localhost/TestWebServices/BooksService.asmx

By default the generated class is in the C# language, but you can change it by adding the /language parameter, as follows:

wsdl /language:VB https://localhost/TestWebServices/BooksService.asmx

By default the generated file also has the same name as the web service (specified in the Name property of the WebService attribute). You can change it by adding a /out parameter to the wsdl.exe command, and you can use a /namespace parameter to change the namespace for the generated class. Here’s an example (split over two lines to fit the book’s page margins):

wsdl /namespace:HowToASPSServices /out:BooksProxy.cs https://localhost/TestWebServices/BooksService.asmx

The next table lists parameters supported by the wsdl tool:

Parameter Short form Description
<url or path>  

A URL or path to a WSDL contract, an XSD schema, or a .discomap document.

/nologo   Suppresses the banner.
/language:<language> /l

The language to use for the generated proxy class. You can choose from CS, VB, or JS, or you can  provide a fully qualified name for a class implementing System.CodeDom.Compiler.CodeDomProvider. The default is C#.

/server  

Generate an abstract class for a web service implementation based on the contracts. The default is to generate client proxy classes.

/namespace:<namespace> /n

The namespace for the generated proxy or template. The default namespace is the global namespace.

/out:<fileName> /o

The filename for the generated proxy code. The default name is derived from the service name.

/protocol:<protocol>  

Override the default protocol to implement. You can choose from SOAP (for SOAP 1.1), SOAP12 (for SOAP 1.2), HTTP-GET, HTTP-POST, or from a custom protocol as specified in the configuration file.

/username:<username>

/password:<password>

/domain:<domain>

/u

/p

/d

The credentials to use when connecting to a server that requires authentication.

/proxy:<URL>  

The URL of the proxy server to use for HTTP requests. The default is to use the system proxy setting.

/proxyusername:<username>

/proxypassword:<password>

/proxydomain:<domain>

/pu

/pp

/pd

The credentials to use when connecting to a proxy server that requires authentication.

 

/appsettingurkey:<key> /urlkey

The configuration key to use in the code generation to read the default value for the URL property. The default is to not read from the config file.

/appsettingbaseurl:<baseURL> /baseurl

The base URL to use when calculating the URL fragment. The appsettingurlkey option must also be specified. The URL fragment is the result of calculating the relative URL from the appsettingbaseurl to the URL in the WSDL document.

/fields  

If set, any complex types used by the web service will consist of public fields instead of public properties.

/sharetypes  

Allows you to add a reference to two or more web services that use the same complex types.

/serverinterface  

Generates an interface with just the methods of the WSDL document. You can implement this interface to create your web service.

 

Important notes:

1. Once you’ve created this file, you need to copy it to the App_Code directory so that the class is available to the pages in your web application.

2. If you’re creating a Windows Forms application ( i.e. rich client application ),  you should add this file directly to the project to be compiled into the final EXE.