Creating Proxy Object of Web Service

text zoom

There are many ways to consume Web Services.

  1. The first way is to use a SOAP Proxy Client Object generated by the WSDL utility, and it provides programmers with their familiar object model that they can use to call methods provided by the generated Proxy Interface.

  2. The second way is to use HTTP-POST and HTTP-GET protocols.

  3. The third way is to use a SOAP standard Request message that parses SOAP response messages with the help of the XMLHTTP COM object that is installed by the Microsoft XML Parser.


WSDL: Web Services Description Language (WSDL) is an XML based protocol for information exchange in decentralized and distributed environments. A WSDL document defines services as collections of network endpoints, or ports. A WSDL document uses the following elements in the definition of network services:

  • Types – a container for data type definitions using some type system (such as XSD).

  • Message – an abstract, typed definition of the data being communicated.

  • Operation – an abstract description of an action supported by the service.

  • Port Type –an abstract set of operations supported by one or more endpoints.

  • Binding – a concrete protocol and data format specification for a particular port type.

  • Port – a single endpoint defined as a combination of a binding and a network address.

  • Service – a collection of related endpoints.


Proxy Class: This proxy class serves as an intermediate between the ASP.NET Web page and the Web service



Consuming Web Service object:


  1. The Asp.Net page instantiates an instance of the proxy class. For e.g. ProxyClassName objproxy = new ProxyClassName();

  2. Once the object is instantiated, then with the help of proxy object, this will make a call to the web service method. For e.g. objproxy.WebMethodName(any Parameter that has to send);

  3. The proxy class marshals the parameter list and makes an HTTP request to the Web service sitting on Web Server 2.

  4. The Web service unmarshals the incoming parameters, runs the method, and marshals the output parameters. These are sent back in an HTTP response.

  5. The proxy class unmarshals the return parameters and passes back the result to the ASP.NET Web page.

Creating a Proxy Class:


Creating a Proxy class involves three steps:


Step 1:- First create the proxy class of the web service using the WSDL tool.

wsdl.exe:-Utility to generate code for xml web service clients and xml web services using ASP.NET from WSDL contract files, XSD schemas and discomap discovery documents. This tool can be used in conjunction with disco.exe.


Run this from the Command Prompt:

C:\Program Files\Microsoft Visual Studio 8\VC> wsdl http://localhost:1508/WebService_New/MyWebService.asmx

Microsoft (R) Web Services Description Language Utility

[Microsoft (R) .NET Framework, Version 2.0.50727.42]

Copyright (C) Microsoft Corporation. All rights reserved.

Writing file 'C:\Program Files\Microsoft Visual Studio



Step 2:- This will create the “Service.cs” file on the specified location. After this compile this Proxy Class to generate the compiled proxy

Class i.e. “Service.dll” Run this from the command Prompt:

C:\Program Files\Microsoft Visual Studio 8\VC> csc /t:library Service.cs

Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42

for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727

Copyright (C) Microsoft Corporation 2001-2005. All rights Reserved.


Step 3:-Place this compiled proxy class in the dll of the Web Site from where you want to access the Web Service.




•  Wsdl.exe contains only one required parameter, a URL or path to the WSDL for the Web service. The following optional parameters can be specified:

•  /language: language – specifies what language the Proxy class should be created in (vb/cs/js).

•  /protocol: protocol – specifies the payload protocol to be used (SOAP, HttpGet, HttpPost)

•  /namespace: namespace – the namespace of the generated Proxy class.

•  /out: filename – the filename of the Proxy class.


Proxy Class inclusion



  1. Add the proxy class to the newly created Web Site

  2. Go to Solution Explorer; right click on that solution à click on “Add Reference”. Below pop-up window appears


  1. Clicking “Ok” will include the proxy class to the solution under “Bin folder”.

  2. Now we can use this proxy class and the methods that are there in the web services.

Note: A proxy class is a class containing all of the methods and objects exposed by the Web service. These methods handle the marshalling of the parameters into SOAP, sending the SOAP request over HTTP, receiving the response from the Web service, and unmarshalling the return value. The proxy class allows the client program to call a Web service as if the Web service was a local component.

Once you create a proxy class using the .NET command-line tool wsdl.exe , a Web service client may invoke proxy class methods, which communicate with a Web service over the network by processing the SOAP messages sent to and from the Web service.




Example: Demonstrate the Creation of Proxy Class and its Usage


using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;


public partial class _Default : System.Web.UI. Page


  protected void Page_Load( object sender, EventArgs e)




  protected void btnCustomer_Click( object sender, EventArgs e)

    { //Fetching the Customer Data from the Proxy Class.



            Service objService = new Service ();

            txtCustomerAge.Text = objService.getEmployeeAge();

            txtCustomerName.Text = objService.getEmployeeName();


    catch ( Exception ex) {









Click On the “Customer Data” Button:


Copyright © 2015 VisualBuilder. All rights reserved