Introduction
To develop distributed systems, Component based Programming is widely accepted. So far number of technologies has emerged to help building distributed systems within the enterprise. Most common Technologies are:
- Distributed Component Object Model (DCOM)
- Common Object Request Broker Architecture (CORBA)
- Remote Method Invocation (RMI)
But in general, the concept of distributed computing stays within the boundaries of the organization as a whole. This is largely due to the ports and protocols to which these organizations are bound. For security reason, many developers and architects are restricted to using only ports 80 and 443 - the ports for HTTP and HTTPS. Even after various attempts, unfortunately for various reasons, no platform fully convinced enterprise architects to run a distributed architecture across the internet.
Interoperability is the ability for different applications to work together, even though they are running on different operating systems, on different hardware architectures, and using different application infrastructure. Programmable web sites that directly link organizations, application, and services would better meet their business needs. This direct linking of applications can be done easily using Web Services and Interoperability is one of the great promises made by the Web services architecture.
Web services is a standardized way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. And they must address these three key issues to be standardized:
- Internet Standards
HTTP and HTTPS must be the initial underlying protocols for Web services to succeed but the technology should be flexible enough to allow any transport protocol to be used.
- Type definitions
Data types that were exposed by Web services must use strongly typed XML.
- Multiple language, platform and vendor support
Web services must not be tied to a particular platform, language or vendor.
The Five components that make up the technical definition of a Web services are:
- Transport (HTTP)
Currently, generally accepted transport protocol is HTTP (with HTTPS for secure connections). However, this doesn't mean that Web Services are tied to HTTP. They can also run on SMTP, SPX, NetBEUI and even on a custom sockets implementation.
- Encoding (XML)
Regardless of the transport protocol used to carry it, the message must be correctly formatted as a valid XML document.
- Standard Structure (SOAP)
XML defines how the message is encoded but doesn't dictate the structure or format of the document. SOAP is a three part definition that specifies an XML structure for the framework of a message known as SOAP envelope:
- The data types that are defined
- A convention for representing RPCs and
- The data returned from them.
- Description (WSDL)
WSDL completely describes the components being exposed and gives the name, data types (using XML Schema Definition), methods and parameters required to call them.
- Discovery (UDDI)
Universal Description Discovery and Integration provides the exact URL of that particular Web Service.
The strongest reasons why we opted Web services for interoperability are:
- Application to application communication across the internet
XML Web Services provide standard defined interfaces called contracts that described the services that they provide.
- Language independent
A XML Web service or a connection to an XML Web Services can be written in any language provided it maintains the XML Web Services Standards.
- Protocol independent
Since they are communicate by using standard Web protocols and data formats, such as HTTP, XML and SOAP, any server that support these standards can access or host XML Web Services.
- Platform independent
Because XML Web Services are accessible through a standard interface, they allow disparate systems to work together.
- Stateless architecture
Each response from a Web services is a new object with a new state. (With ASP.net State Management services to maintain state between requests, we can do)
- Asynchronous
Since the request object from the client application and response object from the XML Web Service are unique SOAP Envelopes, they are asynchronous. They do not require a shared connection.
- Based on W3C
XML Web services are based on World Wide Web Consortium (W3C).
Consuming Java Web Services using a .NET Client.
Let us start our interoperability project by creating a Java Web Services and consuming it by a .NET Client.
Creating a java Web service:
Creating web services in java becomes very simple with lots of tools like AXIS and GLUE in to the picture. Here, I am using Rational Application Developer 6.0 to create the web service.
- Start the Rational Application Developer Studio
- Select File>New>Project launching the new Project wizard.
- Expand the web folder and select Dynamic Web Project and click next.
- In the Dynamic Web Project window enter CincomWS and click Finish.
- Within the project explorer, expand CincomWS and Java Resources folder.
- Right click the JavaSource folder and select New > Class.
- Enter the package name as com.cincom and class name as Welcome.
- Now create a method hiFromCincom and make sure the Welcome.java contains the following lines.
package com.cincom;
public class Welcome
{
public String hiFromCincom(String strNameFromClient)
{
return "HI " + strNameFromClient + ", Welcome to Cincom Java Web Services World.";
}
}
- Select File > New > Other.
- Select show all wizards and select Web Service. Click Next.
NOTE: A window might appear telling you that you need to activate Web Service Development features. Select Always enable capabilities and don't ask again.
- In the Web Services window, select Generate a proxy. You can choose the Test the Web Service option also for creating a test client.
- Click Next.
- In the next window, enter com.cincom.Welcome as the bean and click Next.
- Select the Service web project cincomWS and EAR Project cincomWSEAR.
- In the Java Bean Identity window, check the hiFromCincom method and click Finish.
Now our first Java web service is created. We can see the wsdl with the link
http://localhost:9080/CincomWS/com/cincom/wsdl/Welcome.wsdl
Consuming the web service using .NET client:
- Open the Microsoft Visual Studio .NET
- Select File > New > Project then Visual C# projects and Asp.net Web application and enter http://localhost/WSClient to the location field.
- Add a reference of the above web service.
This can be done in two ways:
I-Using Visual Studio .NET
- Right click on the References and click Add web reference...
- Enter http://localhost:9080/CincomWS/com/cincom/wsdl/Welcome.wsdl to the URL field of the Add web reference and click go.
- Enter cincomWS to the Web reference name field and click add reference
II-Using WSDL.exe
- Open a DOS Command prompt.
- Run wsdl http://localhost:9080/CincomWS/com/cincom/wsdl/Welcome.wsdl it will create WelcomeService.cs file
- Then run
csc /t:library /r:System.dll,System.Web.Services.dll,System.Xml.dll WelcomeService.cs
- The above will created WelcomeService.dll
- Now copy this dll to bin folder of WSClient folder or add a reference (not web reference) of it to the WSClient project.
NOTE: The proxy file created by WSDL.exe is static while the one that are created automatically by the Web reference is dynamic. If we want adding authentication, using WSDL.exe is the best approach as you can guarantee that the file will remain under your control.
- In the design view of the WebForm1.aspx, Add a Text box, one Label and one Button.
- Double click on the Button and make sure the Click function of the button is as follows.
private void Button1_Click(object sender, System.EventArgs e)
{
cincomWS.Welcome cs = new cincomWS.Welcome();
//if You are using the WelcomeService.dll comment the above
//line add a reference of System.Web.Services
//and uncomment the line bellow
//WelcomeService cs = new WelcomeService();
String strName;
if (TextBox1.Text.Equals(""))
{
strName = "Client";
}
else
{
strName = TextBox1.Text;
}
Label1.Text = cs.hiFromCincom(strName);
}
- Now run the project.
- Put a name (YOURNAME) in the Text Box and then click the Button.
- The text of the Label will change to
HI YOURNAME, Welcome to Cincom Java Web Services World.
Consuming .NET Web Services using a java Client.
Now, in this section we are going to create a .NET Web Services and consuming it by a java Client.
Creating a .NET Web Services:
- Start Visual Studio .NET and Select New > Project > Visual C# Project > ASP.NET Web Service
- Write http://localhost/cincomWS on the location field.
- Rename the Service1.asmx to Welcome.asmx
- Create a web method called hiFromCincom as follows
[WebMethod]
public string hiFromCincom(String strNameFromClient)
{
return "HI " + strNameFromClient + ", Welcome to Cincom .NET Web Services World.";
}
- Now run the project
- Check the url http://localhost/cincomWS/Welcome.asmx
- And check http://localhost/cincomWS/Welcome.asmx?WSDL for WSDL
Consuming the web service using java client:
For creating the java proxies for that .NET Web service, we are going to use GLUE, by The Mind Electric, which is a framework for developing and publishing Web services. Get an evaluation version from http://www.webmethods.com/meta/default/folder/0000008629 and install it.
- Run the DOS command prompt
- Make a folder for your own choice say JavaClient
- Change the current working directory JavaClient
- Run the command wsdl2java http://localhost/cincomWS/Welcome.asmx?WSDL
Two files are generated.
IWelcomeSoap.java and WelcomeHelper.java
- Now create a java file Client.java in the same folder
- Past the following code to the file
public class Client
{
public static void main(String[] args) throws Exception
{
String url = "http://localhost/cincomWS/Welcome.asmx?WSDL";
IWelcomeSoap welcome = WelcomeHelper.bind();
String strName;
if (args.length == 0)
{
strName = "Client";
}
else
{
strName = args[0];
}
System.out.println("\n"+ welcome.hiFromCincom(strName));
}
}
- Now compile the files with javac *.java
- Run the client java Client YOURNAME
You will get an output as
HI YOURNAME, Welcome to Cincom .NET Web Services World.