Webservice with Win Forms and Web Forms

Introduction

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

Background

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:

By default, Service1.asmx will be created.

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

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

Now make the option to Release and compile the solution.

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.

<

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.

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.

Now click on “Add Web Reference”.

Click Go Button.

And then click “Add Reference”.

Now in button1_click – write the below code:

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.

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.

Comments and Discussions

Hi, I am trying to call a web service made in Java from Windows Form 2.0. Sometimes it works fine and sometimes it gives an error "The underlying connection was closed: The connection was closed unexpectedly.". When I tried searching the solution on the internet most of them suggested to override the function GetWebRequest(), and in that assign the KeepAlive property to "False" and use ProtocolVersion as 1.0. I tried the above solution but that did'nt work out for me. Kindly suggest a workable solution for my problem.