Monday, July 19, 2010

What is a Web Service ?

A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards. [[www.w3.org]]

Web services are useful in linking applications operating on different network platforms, hardware, software, and databases, performing critical functions for many businesses.


Characteristics of a Web Service :

  • Web services are self-contained : On the client side, no additional software is required other than a programming language with XML and HTTP client support. On the server side, a Web server and servlet engine are required. The client and server can be implemented in different environments. It is possible to Web service enable an existing application without writing a single line of code.

  • Web services are self-describing : The client and server need to recognize only the format and content of request and response messages. The definition of the message format travels with the message; no external metadata repositories or code generation tools are required.

  • Web services are modular : Simple Web services can be aggregated to form more complex Web services either by using workflow techniques or by calling lower layer Web services from a Web service implementation.

  • Web Services are platform independent : Web services are based on a concise set of open, XML-based standards designed to promote interoperability between a Web service and clients across a variety of computing platforms and programming languages.

Categories of Web services :

  1. Business information : A business shares information with consumers or other businesses to expand its scope. [Ex: News Streams, Weather Reports, or stock quotations.]

  2. Business integration : A business provides transactional, "for fee" services to its customers. In this case, the business becomes part of a global network of value-added suppliers that can be used to conduct commerce. [Ex: Reservation Systems, and Credit Checking]

  3. Business process externalization : In this case, the business uses Web services to dynamically integrate its processes. [Ex: dDfferent companies to combine manufacturing, assembly, wholesale distribution, and retail sales of a particular product.]

Service roles and interactions :


A network component in a Web Services architecture can play one or more fundamental roles as,

  • Service Providers : Create and deploy their Web services and can publish the services through a service registry, such as a UDDI(Universal Description, Discovery, and Integration) Business Registry which is a registry used by business around the world to list themselves on the Internet.
  • Service Brokers : Register and categorize published services and provide search services. [Ex UDDI]
  • Service Clients : Use broker services to discover a needed WSDL-described service and then bind & call the service provider.

[Source : http://help.eclipse.org/]

Binding involves establishing all environmental prerequisites(security, transaction monitoring, and HTTP availability) that are necessary to successfully complete the services.

Wednesday, July 29, 2009

Create PHP 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.


$params->num1 = 1;
$params->num2 = 2;

$client = new SoapClient("http://localhost:8080/CalculatorService/services/Calculator?wsdl");

try {
$reply = $client->getSummation($params);

echo $reply->return;

} catch (SoapFault $exception) {
echo $exception;
}

?>

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.

Wednesday, May 13, 2009

Check Your Deployed Web Service

I will assume that you have successfully deployed our CalculatorService in the Apache Tomcat. If not follow this link to create web service Develop and Debug web services using Axis, Eclipse and Tomcat

1.To check the deployed service type the following URL in the browser.
http://localhost:8080/CalculatorService/


2. Then you will see the flowing screen.



3. Then click on Service to view the list of all the available web services deployed in this server. Currently we have only one deployed web service. Then you will see the following list of services page.


4. To check the service definition click on service name "Calculator" or type following URL in the browser.

http://localhost:8080/CalculatorService/services/Calculator?wsdl

5.To check whether service is working properly, check the following URLs.

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

You see an xml file containing result as below. You can change the arguments to see the service working.

Check Operation getSubtraction:
http://localhost:8080/CalculatorService/services/Calculator/getSubtraction?num1=1&num2=2

You see an xml file containing result as below. You can change the arguments to see the service working.


Check Operation getDivision:
http://localhost:8080/CalculatorService/services/Calculator/getDivision?num1=1&num2=2

You see an xml file containing result as below. You can change the arguments to see the service working.

Check Operation getMultiplication:
http://localhost:8080/CalculatorService/services/Calculator/getMultiplication?num1=1&num2=2

You see an xml file containing result as below. You can change the arguments to see the service working.


Share your comments.............. :)

Tuesday, April 7, 2009

Develop and Debug web services using Axis, Eclipse and Tomcat

In this article, I am going to describe how you can create simple web service using axis and eclipse and steps needs to deploy it in tomcat.

My Eclipse Platform environment details listed below,


Version: 3.3.0
Build id: I20070621-1340

(c) Copyright Eclipse contributors and others 2000, 2007. All rights reserved.
Visit http://www.eclipse.org/platform

This product includes software developed by the
Apache Software Foundation http://www.apache.org/
Create Web Services using axis and eclipse

I will create a simple calculator service with 4 simple service functions to manipulate addition, subtraction, division and multiplication of two given real numbers.

  • getSummation(double num1, double num2)
  • getSubtraction(double num1, double num2)
  • getDivision (double num1, double num2)
  • getMultiplication(double num1, double num2)


Step 1: Create a dynamic web project.

1. Open your eclipse IDE with new work space for clarity. Then change your perspective to Java EE by selecting Window -> Open Perspective -> Other



2. Go to Window -> Show View -> Project Explorer.

3. Then Click on Mouse Right Button on Project explorer window and select New - > Project.

4. In New project wizard select Dynamic Web Project and click Next.


5. In Dynamic Web Project wizard provide project name (Ex: CalculatorService).

6. If you already define target run time select it or click on New button to add target run time.

7. In New Server Runtime wizard select your server.(I will select Apache Tomcat 5.5 since i have installed it.) and click Next.

8. Browse and select for Tomcat Installation Directory (Ex: C:\Program Files\Apache Software Foundation\Tomcat 5.5). To add new Java Runtime Environment click on Installed JREs and click on Add buttons and provide JRE home directory,or used your workbench default JRE and click Finish.




9. In Configuration section keep default value as shown bellow and click Finish to complete dynamic web project creation.



10. Now you can see in Project Explorer window with created dynamic project folder content and servers as,



Go to Window -> Show View -> Others -> Server -> Servers to get available Servers in your workspace and double click on the server already added in server explorer window to open configuration. Under Server location select option "Use Tomcat installation (take control of Tomcat installation)".




11. Mouse RB click on java resource section in project explorer and add new package(Ex: org.blog.webservice)




Step 2: Create a simple Calculator class.

12. Mouse RB click on above created package and add new Class Calculator with following code.


package org.blog.webservice;

/**
*
* @author WGPM Rangalal
*
* Axis Service Sample.
*
* Visit http://rangalal.blogspot.com/
*/

public class Calculator {

public double getSummation(double num1, double num2) {

return num1 + num2;

}

public double getSubtraction(double num1, double num2) {

return num1 - num2;

}

public double getMultiplication(double num1, double num2) {

return num1 * num2;

}

public double getDivision(double num1, double num2) {

if (num2 != 0)

return num1 / num2;

else
return -1;

}

}

Step 3: Create an axis service from this class.

13. Mouse RB click on Calculator class in project explorer and select New -> Other ->Web Services wizard and select Web Service on that wizard and click Next.



14. Select Web Service Runtime as Apache Axis 2



15. Select web server run time as Apache Axis2 and server as Tomcat 5.5 under existing servers and click OK.



16. select check box Publish the Web service in step 14 and click Next. You will end up with flowing error message. Click on Detail button to see more description about error.



17. To Solve above error download axis2.war file and copy it to \webapps directory. Then go to Window -> Preferences -> Web Services and select Axis2 Preferences.



18. Select Axis2 Runtime tab and browse for axis2.war content directory (Ex: C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps). Then wizard will load the runtime and you will display following message. "Axis2 runtime loaded sucsesfully !!!"



19. Now start step 3 (13 - 15) and click Next. then wizard will load the axis2 runtime to dynamic web prokect webcontent directory.



20. In Axis2 Web Service Java Bean Configuration select option Generated default services.xml file and click Next.



21. Then click Start server button to start server.



22. After server start click Next button and if you want you can publish your web service at UDDI (Universal Description, Discovery and Integration)and click finish.


23. Now is time to Check Your Deployed Web Service.


Share your comments.............. :)