Click here to Skip to main content
14,302,993 members

Webservice with Win Forms and Web Forms

Rate this:
3.84 (9 votes)
Please Sign up or sign in to vote.
3.84 (9 votes)
6 May 2009CPOL
Basics of Web service, and how to use it


This document will explain how to create a basic web service, and how to use it with Windows application and web application.


Here, my web service has been created in VS 2008 [Framework 3.0]. One consumer application is Windows application which is VS 2005 [Framework 2.0] application and another consumer application is web application which is VS 2003 [Framework 1.1]. This means, here I tried to cover all possible combinations.

Using the Code

1.  Create New Web Service [.NET 2008]

First of all, create a new web service:

Image 1

By default, Service1.asmx will be created.

Image 2

Delete Service1.asmx which is default. And add a new Service.

Image 3

Here by default, one web method HelloWorld will be there:

Image 4

Now make the option to Release and compile the solution.

Image 5

Again make the option to debug and try to run the web service by using F5.

First time, it will popup the dialog saying “Debugging Not Enabled”. By default “Modify the web.config….” option will be selected. Keep it selected and click OK.

It will run your web service and you will see something like below, it means, your web service called UserActivity with one method Helloworld is ready.

Image 6<

Now, go to IIS [start – run – InetMgr] and locate your folder LogEntryService. After that, right click on this folder, go to property.

Click on Create which will create a virtual directory in IIS.

Image 7

2. Consumer Windows Application [.NET 2005]

Now, I will create a separate Windows application which will be in .NET 2005, which will consume the web application.

Image 8

Now click on “Add Web Reference”.

Image 9 Image 10

Click Go Button.

Image 11

And then click “Add Reference”.

Now in button1_click – write the below code:

Image 12

See the magic!!!!!!

So, here my Web Service has been created in .NET 2008 with VB.NET and my consumer application is a Windows application in .NET 2005 with C#.

3. Consumer Web Application [.NET 2003]

Now, let us create a .NET 2003 Consumer web application which will be a Consumer application.

Image 13

As this project is not directly under localhost, and as it is under localhost/RnD/….

You need to create a virtual directory for this folder by going to IIS -> Select folder Web2003_WS -> Right Click -> Properties -> Create on Directory tab [First tab].

Also, make sure that you have selected version 1.1 for 2003 application.

Image 14

Now, come back to the .NET side and the same as in the above application, in Solution explorer, under References, select Add web reference, add http://localhost/LogEntryService/UserActivity.asmx.

Image 15

Now in button1 click, add the below code:

Image 16

Points of Interest

All the above combinations of web service and consumer application are in working condition and are well tested.




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Computer Aid Inc.
United States United States
No Biography provided

Comments and Discussions

GeneralWeb Service Error : "The underlying connection was closed: The connection was closed unexpectedly." Pin
ganesh_barhate27-Jul-10 19:50
memberganesh_barhate27-Jul-10 19:50 
Generalgood article Pin
Donsw13-Jun-09 5:22
memberDonsw13-Jun-09 5:22 
GeneralRe: good article Pin
ahkayastha10-Jul-09 10:35
memberahkayastha10-Jul-09 10:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 6 May 2009


34 bookmarked