Monday, June 29, 2009

Create Dot Net Client to Access Web Service

In this article i will assume that you have already create a Calculator Web Service and deployed it on tomcat web server. If not please go and create your sample web service following the article Develop and Debug web services using-Axis, Eclipse and Tomact.

1. Open Microsoft Visual Studio and select File - > New -> Project -> Console Application and provide the storage location and click OK.



2. You can see default solution content in Solution Explorer window as shown bellow.



3. Program.cs file will have following initial code.

using System;
using System.Collections.Generic;
using System.Text;

namespace CalculatorClient
{
class Program
{
static void Main(string[] args)
{
}
}
}

4. Mouse right click on Reference in solution explorer window and click Add Web Reference.



5. In the Add Web Reference window provide Web Service URL and click Go button. It will display description of Web Service methods. Then give the Web Reference Name and click Add Reference button to add it to Solution Explorer.

URL : http://192.168.46.1:8080/CalculatorService/services/Calculator?wsdl
Web Reference Name : CalculatorService



6. You can see the Solution Explorer will display newly added Web Reference and other related References.



7. Add the following code base inside Main method in Program.cs file.

CalculatorClient.CalculatorService.Calculator calculatorService = new CalculatorClient.CalculatorService.Calculator();

double extraDouble;
bool extraBool;

// the getSummation method signature is getSummation(double, bool,double, bool, out double, out bool)
calculatorService.getSummation(10, true, 12, true, out extraDouble, out extraBool);
Console.WriteLine(extraDouble);
Console.WriteLine(extraBool);

8. Run the code base and you will see the following output.



9. Now you can debug both Dot Net Console client and Java Web Service together .

Debug the Deployed Web Service

In this article i am going to explain how you can debug your web service deployed in tomcat, with eclipse. If you haven't yet deploy it please go and read check your deployed web-service

1. Mouse Right button click on ID where you want to add break point and select Toggle Breakpoint as shown bellow.



2. In server explorer mouses right click on Tomcat Server and select Debug option as shown bellow.



3. Click the URL calling the Web Service function with its arguments as shown in following URL.

http://localhost:8080/CalculatorService/services/Calculator/getSummation?num1=1&num2=2

4. Then you will be able to debug the Web Service code with eclipse IDE.