In this post we are going to understand
how create web service proxy and consume
service into console application(Client).
Building
Web Service Clients using the .NET Framework:
Clients
communicate with Web Services using standard web protocols, using XML-encoded
messages to send and receive messages between themselves. This makes it
possible for client applications running on any platform to access web services
as long as they use standard web protocols, and understand the XML-encoded
messages.
There
are three protocols that web clients can use to communicate with web services
namely,
- HTTP GET
- HTTP POST
- SOAP.
The
various steps that are involved in creating a Web Service Client using C# and
the .NET Framework are as follows:
- Generate a Proxy for the Web Service
- Compile the Proxy as a DLL library
- Create a Visual C# - Console Application Project
1.
Generate a Proxy class for the Web Service
.NET SDK provide WSDL.exe utility to generate proxy
source code for an existing web service.WSDL.exe utility take a WSDL file as
input to generate proxy source code.
we can generate proxy source code for the actual web
service as shown below:
1.Go to .NET Command prompt
2.Type following command to create proxy source
code
WSDL
http://hostServer/WebserviceRoot/WebServiceName.asmx?WSDL
(Created new proxy class file and it's located into
default .NET command prompt folder)
OR
WSDL /out:myProxyClass.cs http://hostServer/WebserviceRoot/WebServiceName.asmx?WSDL
if we want to create proxy class as specific user
defined name, we can specify class name in next to out keyword.
2.
Compile the Proxy class as a DLL Library
We
can compile the C# generated proxy class file into a dynamic link library (DLL)
and then add a reference to this DLL to any project we want to consume service.
3. Create
a Visual C# - Console application
- Create a new Visual C# console application in order to consume web service and add a reference to the already created DLL(based on point no.1 & 2).
- We create an instance of the proxy class and call functionality wherever required.
- Build the project file and run the client.