VisualBuilder
  Home > Csharp > Tutorials > Consuming Web Services - 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
 Consuming Web Services
  << Prev: Web Service Next: Creating Proxy Object of Web Service >>

A Web Service is an external interface provided by a Web site that can be called from other Web sites. For example, a financial company may make up to the minute stock quotes available via Web Service for those who do their trading with that company. This information could be read from a Web page and displayed, or read from a stand-alone application on a customer's desktop computer.


 


Client Communicate through web service:


 


SOAP over HTTP SOAP over HTTP




XML XML


 


Location 1                                                                                                        Location 2


 


Soap calls are remote function calls that invoke methods executions on Web Service components at Location 2. The output is render as XML and pass back to the Location 1 where the user wants to access the Web Service.


At Location 1, the user need to consume some of the functions of the web service that is available on the internet, to make the remote function calls (RFC). All the processing can't be done on the remote machine, therefore, we have to create the proxy of the web service from where we can process our data. This whole process is also called as marshalling of data.


Due to security threats, we create the proxy of the server object here it is web service. That means we are creating a " proxy object " to act on behalf of the original Web service. The proxy object will have all the public available data interfaces as the original Web service.


 


Consuming a Web Service



The following are the steps to call/consume a webservice.


 


Step 1: Create a Web Service project and run it so that no compilation error exists.


Step 2: Create new Web Site that will consume this web site that is there in your system using the VS.Net. Create New Web Site with the name: Web Site Name that will consume web service: WebService_Consume.


Step 3: Once you are done with the creation of the new site that will consume the web Service. Let example the web service run as this URL: http://localhost:1508/WebService_New/MyWebService.asmx


 


 




 


Step 4: Right click on the solution, Click on “Add Web Reference”. This will open up a new pop-up window where you can specify the URL name of your web service .


 




 


Here we specify the web service URL and if you look at the right panel there is Web Reference Name: localhost [This the default name that is there].


 


Step5: We specify “localhost_myWebService” name for the web reference. This will include 3 files under this folder.



  • MyWebService.disco

  • MyWebService.discomap

  • MyWebService.wsdl


 


Step6: Look Inside the contents of the “disco” file


 


<?xml version="1.0" encoding="utf-8" ?>


<discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/">


<contractRef ref="http://localhost:1508/WebService_New/MyWebService.asmx?wsdl" docRef="http://localhost:1508/WebService_New/MyWebService.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" />


<soap address="http://localhost:1508/WebService_New/MyWebService.asmx" xmlns:q1="http://tempuri.org/" binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />


<soap address="http://localhost:1508/WebService_New/MyWebService.asmx" xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />


</discovery>


 


Step7: Look Inside the contents of the “discomap” file


 


<?xml version="1.0" encoding="utf-8" ?>


<DiscoveryClientResultsFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">


<Results>


<DiscoveryClientResult referenceType="System.Web.Services.Discovery.DiscoveryDocumentReference" url="http://localhost:1508/WebService_New/MyWebService.asmx?disco" filename="MyWebService.disco" />


<DiscoveryClientResult referenceType="System.Web.Services.Discovery.ContractReference" url="http://localhost:1508/WebService_New/MyWebService.asmx?wsdl" filename="MyWebService.wsdl" />


</Results>


</DiscoveryClientResultsFile>


 


 


Example: Demonstrate the Consumption of the Web Service in the Web Site


 


 


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 Button1_Click( object sender, EventArgs e)


    { //Consuming the WebServices through Add Web Reference


    //Fetching the Value from the Web Services


        localhost_myWebService. Service objServiceConsume = new localhost_myWebService. Service ();


        txtName.Text = objServiceConsume.getEmployeeName();


        txtAge.Text = objServiceConsume.getEmployeeAge();


    }


}


 


Output:


 




 


Click on the Fetcher button: This will fetch the value from the Web Service.


 




 


 


 


  << Prev: Web Service Next: Creating Proxy Object of Web Service >>
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
Skype vs. sipcall
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

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