VisualBuilder
  Home > Csharp > Tutorials > Creating Proxy Object of Web Service - C# Tutorial
Tell a friend
Link to us
Total Members
      Members: 84606
     
Sitemap Forum Chat
Home
C# Tutorial Home
1 . Introduction to C sharp
2 . Control Statement: Selection Statement in C sharp
3 . Control Statements – Loops Statement
4 . Methods
5 . Namespaces
6 . Introduction to Classes:
7 . Inheritance:
8 . Polymorphism
9 . Properties
10 . Indexers
11 . Structs
12 . Interfaces
13 . Delegates:
14 . Exception Handling:
15 . Attributes
16 . Enums
17 . Encapsulation
18 . Parameter Passing in C sharp
19 . Method Overloading
20 . Database Interaction Using C sharp
21 . Operator Overloading in C sharp -1
22 . Operator Overloading in C sharp -2
23 . Operator Overloading in C sharp -2
24 . Sockets
25 . DNS [Domain Name System]
26 . Working with Files
27 . Generating Help File in C sharp
28 . Code Access Security
29 . Multi-Threading
30 . Globalization and Localization -1
31 . Working with Registry in C sharp
32 . Globalization and Localization -2
33 . Windows Service
34 . Web Service
35 . Consuming Web Services
36 . Creating Proxy Object of Web Service
37 . Creating an XML document
38 . Reading XML document in C sharp
39 . Using XMLWriter class to Write XML document in C sharp
40 . Assembly Information : Getting Permission set of the assembly
41 . Creating your own Permission Set
42 . Using C sharp Socket
 
Csharp Group Home
Csharp Discussion (7)
Csharp Members (2250)
Csharp Resources
Csharp Source Code (35)
Csharp Articles (0)
Csharp Blogs
Csharp Jobs
Csharp Components (5)
Csharp Books
Csharp Websites (25)
Csharp News (17)
Csharp Q & A (4)
- Csharp Ask Question
- Csharp Questions
- Csharp Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (432 )
Source Code (3217 )
Articles (11 )
Components (1589 )
News (880 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Csharp Tutorial
 Creating Proxy Object of Web Service
  << Prev: Consuming Web Services Next: Creating an XML document >>

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


8\VC\Service.cs'.


 


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:


•  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.


    try


        {


            Service objService = new Service ();


            txtCustomerAge.Text = objService.getEmployeeAge();


            txtCustomerName.Text = objService.getEmployeeName();


        }


    catch ( Exception ex) {


        Response.Write(ex.Source);


        }


    }


 }


 


 


Output:




 


Click On the “Customer Data” Button:



  << Prev: Consuming Web Services Next: Creating an XML document >>
Csharp Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
Hosted Exchange, SDSL
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising