Consuming a web service To a Client

Monday, 29 August 2016

Consuming a web service To a Client

Consuming a web service

Main purpose of creating a web service is to use the service from same server different application or different server . So to access a web service from another application the following task needed to be performed. To know how to create a web service click here.

  •  We have to add the service reference to our client application 
  •  Give the reference a meaning full name 
  •  Create a object of the service 

Creating the Proxy

before using web service to the client a proxy must be created which is registered with the client application.Then the  client application makes the calls to the web service as it were using a local method.The proxy takes the calls, wraps it in proper format and sends it as a SOAP request( For details about SOAP Click here) to the server. This protocol is used for exchanging web service data.When the server returns the SOAP package to the client, the proxy decodes everything and
presents it to the client application.This Process is describe in this picture

Now Take the following steps for creating the proxy:
Step (1) :In my case, client is a windows application. so to add web reference first right click on application then select add service reference, Now Click on Advance it will open up service reference settings there at the end of the window click add web reference.


Step (2) : Now add web reference window will open and you have to copy the hosted web service address to the URL address bar. A meaning full web service reference name should be given then click on add reference. It will add the service reference with the client application now from the client application you can create object of the service reference and call the web service method.



Step (3) :  write down the below code to create object of the service .
                  ConsumeService.Service1  obj = new ConsumeService.Service1();