This article describes how to consume web service with Win Form Application which fetches the data from Oracle 10g Database and how to use that data into your client application. The Win Form Client simply calls a Web Service through SOAP message containing a request for the method. The Web server process particular method called by client and serializes the output in SOAP message and send back to the client in pure XML format.

In first step we create a simple Web Service which connects to Oracle 10g Database and then use it in Windows Form.

1. Create new ASP.Net Web Service Application with name MyWebService.

yagnik1 Integration of Web Service in Win Form using Oracle 10g


2. Application contains service.vb and service.asmx files. Service.vb file contains your code for web method and services.asmx file provides interface for web service functionality. It contains one default method HelloWorld() with return type as string that returns “Hello World” to the client. Notice that it contains tag _ on the top of the function. It indicates to the compiler that this method is exposed by the web service. It may also contains some attributes like Description of the method etc.

yagnik code 1 Integration of Web Service in Win Form using Oracle 10g

 Here, we add one more method which access data from Oracle 10g database and returns the Dataset to the client. Here, WebMethod contains Description tag for the method description. You can also manage the session and catching for the web service like EnableSession:=True.

yagnik code 2 Integration of Web Service in Win Form using Oracle 10g

3. You can test the result before using in Windows Forms by running the Web Service Application by pressing F5. Here you can see that, it contain two methods FillDataset() and HelloWorld() with description of both the methods.

yagnik2 Integration of Web Service in Win Form using Oracle 10g

Click on FillDataset method and invoke it. It should display the result Dataset in XML Format.

   yagnik3 Integration of Web Service in Win Form using Oracle 10g

4. Now, you have to publish this web service to use it in your windows form application on your web server.

yagnik4 Integration of Web Service in Win Form using Oracle 10g

5. Then, go in IIS and select property menu from popup on MyWebService folder and create the Application as shown below to access it in Win Forms.

yagnik5 Integration of Web Service in Win Form using Oracle 10g

6. Now, create a new Project using Windows Application to use web service with name TestWebService.

yagnik6 Integration of Web Service in Win Form using Oracle 10g

7. Next, add Web Reference in Solution explore as shown below:

yagnik7 Integration of Web Service in Win Form using Oracle 10g

In the next screen, type the URL where you have published the web service and click on Go Button. It will show the result as below. Type the name ‘TestWS’ to create the instance for your Win form. It will add the web service in your project.

yagnik8 Integration of Web Service in Win Form using Oracle 10g

You can see that TestWS instance is created in Win Form and now it is ready tofor use.

Notice that it contains property ‘Web Reference URL’ which shows the URL where the web service is located. You can also change it at runtime in case of change in location of web service in future.

yagnik9 Integration of Web Service in Win Form using Oracle 10g

8. Now in your form put Button called ‘Call Web Service’ and write code like this to call web method.

yagnik10 Integration of Web Service in Win Form using Oracle 10g

Here, you have to import TestWebService namespace to use the functionality of web methods.

yagnik code 3 Integration of Web Service in Win Form using Oracle 10g

So, now you can fetch the data from Oracle database through Web Service and use it in your Win Form Application as per requirements like this.

yagnik code 4 Integration of Web Service in Win Form using Oracle 10g

Â

Â

Â

Â

Â

Â

Â

Â

Â

Â

In case of change in location of Web Service on the server you can also assign dynamic path to web service from where you want to call it, like :

yagnik code 5 Integration of Web Service in Win Form using Oracle 10g

Conclusion:

So, it is not very difficult to use Web services in the Win Form application. I hope, this article is helpful to all developers who are beginners in using Web Service and it provides them sufficient guidance on how to use the web service in their windows application.

Author:

By Yagnik Jadav

Yagnik Jadav is working as a Senior Software Engineer with Semaphore Infotech Pvt. Ltd, a renowned IT company based at Ahmedabad, India . He has more than 2 years of experience in software development. He is very proficient working in Microsoft Technologies, especially VB.Net. You can contact on email: yagnik@semaphore-software.com