Monday, August 6, 2007

Integration of Web Service in Win Form using Oracle 10g

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.


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.

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.


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.

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

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

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.

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

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

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.

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.

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

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

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.

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 :

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

0 comments: