Using Webservice from .dll (Library)

You know about, Web Services in ASP.NET. If yes, then you must be aware of methods of accessing Web Method in another Project (windows or Web). Here is another method to Access/consume web service via a offline dll.

I hope you all must be familiar with Web-services in ASP.NET.
"A Web Service is programmable application logic accessible via standard Web protocols". This Definition is taken from MSDN Library.

Today I am not here to tell you how to Create a Web Service. I am here to tell you that how to consume a Web-service in your Application on Offline Mode.

Generally, it is the concept that is Given at the time of Creating Web Service and in Institute is that you must keep Service alive / running to consume its Feature. Means you create Web-service, then Publish it on the Host / IIS (Internet Information Service). Then You have to Add Service Reference to the Running Web Service in project that you want to Consume by clicking Add Reference and giving path etc and only after doing that you are able to Access the Web Service (send or receive messages over service protocols).

I am here to tell you, how to consume the Service in the another Machine or Multiple applications without using any Live running Service and without Uri's my using dll.

We First Create a Web Service, I created a Service here which have some methods. Lets see the snapshot while running in IE.

Web Services1

To Use It in Offline mode, means we have to create dll (Dynamic-Link Library). Lets move to procedure.
Open Visual Studio Command Prompt with Administrator Privilege. We will take Help of wsdl utility. WSDL, have you heard it before? No. WSDL means Web Service Description Language Utility provided by Microsoft inside Visual Studio. We will here generate a Code file from Web Service and them convert it into dll.

On your Visual Studio Command Prompt type below command :

wsdl /l: cs "path of service"

// wsdl /language: cs "path of Service"


wsdl /l:cs http://localhost/MyService/Service.asmx

Type the above code, Replace Path of Service with your actual Service path which will look like in Example and will be up always.
In above Code: we have called wsdl.exe utility and set Language Option to CS (C Sharp), you can choose among CS, VB, JS, VJS, CPP. While Default is C Sharp abd /l is short code for /language for setting options.

Web Services2

As you see, it tells that, it has Write a file named Service.cs. Now the Next task is to Create a dll of this CS File. Note we can't create dll directly from Web Service.

Now we will take help of Compiler, once again open Visual Studio Command Prompt and type below code:

csc /t : library "path of service.cs file"

As we have created .cs file in above statement, so we have called C Sharp Compiler (csc) utility here to convert to library and set target as library.
You can get more help on these topics by searching help on Command Prompt like "csc /?" etc.

Lets see what happened, when the above code is Executed.

Web Services3

Lets see the Location where we created file. In above case it is System32 folder. Now copy the File (.dll) from location where it is Created and add in to Project like this.

Web Services4

Now just use the services anywhere in your Project, either it is Windows Application or Web Applications. Accessing Method is same as accessing a Class inside App_Code file.

Service obj = new Service();
GridView1.DataSource = obj.ShowCustomer();

All the Best and Hope you enjoyed. Leave comments below to respond.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: