Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Integrating J2EE and .NET Web Services

Integrating J2EE and .NET Web Services

Many articles have claimed that Java 2, Enterprise Edition (J2EE) and .NET Web services are interoperable. What does this mean from a developer's perspective? What issues and problems arise as you actually do the work?

For our purposes, I'll define Web services as self-contained, modular business applications that have open, Internet-oriented, standards-based interfaces. The standards I'm referring to are Simple Object Access Protocol (SOAP) and Web Services Definition Language (WSDL). SOAP is a lightweight XML-based message format for communication between Web services. WSDL is a schema that describes the way in which a Web service is to be used. WSDL documents answer the following questions about a Web service: What data is exchanged, how do you interact with the service, and where is the service located? When I refer to term interoperability between Web services, I mean that you can call J2EE Web services from a .NET client application and the reverse is also true.

Analysts have projected that J2EE and .NET will each have approximately 40% of the Web services that will be implemented on their platform. This means that for a customer to be able to utilize all the Web services that will be available in the future, the platforms need to interoperate. Companies from both camps are working together to ensure interoperability. Several standards bodies have been formed to drive interoperability between the various Web services platform providers. For example, both SOAPBuilders and the Web Services Interoperability Organization (WS-I) are involved in interoperability efforts.

To prove that simple J2EE and .NET Web services can interoperate, two things must be demonstrated. One, a .NET Web services client should be able to call and receive a response from a J2EE Web service, and two, a J2EE Web services client should be able to call and receive a response from a .NET Web service.

Case Study
In the interest of reusing code and knowledge, the same application was used to prove both points. I started with an existing J2EE application that uses servlets, JavaServerPages (JSPs), and Enterprise JavaBeans (EJBs) that I converted into a Web service. This application allows a field agent to view, edit, and create orders for a fictional construction company. The field agent is also able to sort existing orders by customer name,employee id, or order status.

Calling a J2EE Web Service from a .NET Client
Making Orders a J2EE Web Service

In order to reuse as much code as possible, I used the EJBs that had been written and deployed on WebLogic Server to implement the business logic on the back end. First, I needed to create a Web service that exposed the methods of the EJBs. To create a Web service in BEA WebLogic Workshop, I used the wizard provided and named it Orders (see Figure 1). This generates a Web service file with the name Orders.jws. Using the WebLogic Server 7.0 and WebLogic Workshop Web service runtime environment, I added the EJBs to my Web service with controls. Controls are a mechanism in WebLogic Workshop for interacting with resources from within a Web service. They can be interfaces to databases, EJBs, JMS queues, or other Web services.

Calling the EJBs from the Web Service
In order to call the EJBs from my Web service in WebLogic Workshop, I need a handle to an EJB and this is what the control does. As you can see in the following code sample, the SearchEJB variable is my control; I call a particular method, getOrdersByID, and pass it the incoming parameter, ID. This is where the WebLogic Workshop tool really provides value to the developer. I didn't have to worry about getting references to the home and remote interfaces for the EJB. The control hides this complexity and simplifies the coding required to interface with the EJB. The jws:operation tag in the code sample is a signal to the WebLogic Server that this method is part of the Web service's public contract and is available for clients to invoke.

/**
* @jws:operation
*/
public ordermasterfields[] getOrdersByID(String ID)
{
ordermasterfields[] orderArray = null;
try{
LinkedList orderList = SearchEJB.getOrdersbyID(ID);
orderArray = getArray(orderList)
}
catch(Exception e){
System.out.println("*** In getOrdersByID method *** \n
Exception is: " + e.getMessage());
}
return (orderArray);
}

Once I added the EJBs to the Web service, I carefully checked the data types that were being returned from the EJB methods. I wanted to make sure that each of these data types is serializable so that I can return them over the wire to the Web service client. Notice in the code above that my EJB method returns a LinkedList that is not serializable. There are two possible solutions to this problem. I could choose to either change the code in the EJB to return a serializable data type and redeploy the EJB, or I could convert the data type inside the Web service before returning it to the client. I chose the second option for simplicity: I didn't have to redeploy the EJBs and I could still use the original front-end Web application if necessary. Since LinkedLists are not serializable, I converted the Web service method to return an array of "ordermasterfields". This class, ordermasterfields, is user-defined and will be included in the WSDL document so the client knows what the user-defined types are. The getArray method performs the conversion.

The next step is to generate a WSDL document for use by a .NET client. In WebLogic Workshop I simply clicked on the "Generate WSDL Document" button and it automatically generated the WSDL document for me. I'm now ready to create a client that will use the Orders J2EE Web service. Notice that all we've really done is add a new Web service interface to the EJBs. As a matter of fact, the Web application front end that I started with is still usable since the EJBs have not been changed. In addition to returning HTML from the original Web application, we are now returning an XML document that contains an array of Orders via SOAP from our Web service.

Creating a .NET Client for the J2EE Orders Web Service
Now that I've created a J2EE Web service I need to create a .NET client that will access it. In Visual Studio .NET, the first step is to import a WSDL document into the ASP.NET Web services client by adding a Web reference to the client through a wizard in Visual Studio .NET. You can either point to a file on your local system or to the URL of a Web service on the Internet. I added the Web reference for the J2EE Orders Web service and Visual Studio .NET automatically generated a client proxy file. This file maps all the operations and data types from the WSDL document to a client proxy code file, Reference.cs, on the client side. Then, all that is necessary is to create a variable that uses the client proxy to call methods on the Web service. The following code fragment contains excerpts from the Reference.cs file that show where to find the Web service and defines return types for a particular method.

public Orders() {
this.Url = "http://localhost:7001/Orders/Orders.jws";
}

public ordermasterfields[] getOrdersByID(string ID) {
object[] results =
this.Invoke("getOrdersByID", ne object[] {ID});
return ((ordermasterfields[])(results[0]));
}

Now that I have added the Web reference and Visual Studio .NET has created a client proxy, I need to create an instance of the Web reference, Orders, and invoke a method. This is all the code I need to write to invoke a particular method on the Orders Web service.

using OrderWebApplication.WebReference1;

WebReference1.Orders orders = new WebReference1.Orders();

WebReference1.ordermasterfields[] ordersResult =
orders.getOrdersByID(userName);

.NET has a concept of strict separation between the presentation and the implementation of code. They use what they call a code-behind file that is tied to the WebForm page that contains all the code (see Figure 2). All of the presentation is handled in the WebForm.aspx file, which is an ASP.NET page, and all code is written in the WebForm.aspx.cs file. The idea is the same as a JSP file where HTML is the presentation or static content and dynamic content is inserted in JSP tag sections. .NET simply extended that and moved the embedded code sections to a separate code file. I could still implement the ASP.NET page with combined HTML and ASP.NET code in the same file if I wanted to. I also created new presentation code with ASP.NET pages that duplicates what was already available on the J2EE platform, but this is not covered in this article.

Request and Response Code
Now that I have both a client and a Web service, let's look at what happens when I make a request to the Web service. With Web services, SOAP request and response messages are sent back and forth either asynchronously or synchronously. Here I show only the portion of the SOAP message that pertains to the Web service method I am invoking. I am calling the getOrdersByID method and passing it an ID parameter with a value of JANE.

<getOrdersByID xmlns="http://www.openuri.org/">
<ID>JANE</ID>
</getOrdersByID>

In response from the Web service, I get an array of ordermasterfields that represents all orders with an ID of JANE.

<ArrayOfordermasterfields xmlns="http://www.openuri.org/">
<ordermasterfields>
<orderNbr>1</orderNbr>
<customerNbr>100</customerNbr>
<employeeID>JANE</employeeID>
<customerName>Johns Lock Shop</customerName>
......
</ordermasterfields>
</ArrayOfordermasterfields>

Figure 3 is my completed .NET client and J2EE Orders Web service.

Calling a .NET Web Service from a J2EE Client
At this point I need to prove that a J2EE Web service client can invoke a .NET Web service. In this case I didn't have a preexisting .NET application so I created a .NET Web service from scratch.

Creating a .NET Web Service
I decided to re-create the same Orders application since I already knew how this application worked on the J2EE side. First I created a new database using Microsoft Access to duplicate the tables. Second, I added ADO.NET objects to access the database and exposed those methods through a Web service page, Orders.asmx.

In order to make the method available through the Web service interface I added the [Web Method] designation in front of the method signature. The DataSet type is a new data type that is currently available only in .NET languages. This means that the Web service client must be able to translate this data type to an equivalent one in the language it implements. In this case, the J2EE client must be able to convert the DataSet type into a Java equivalent.

[ WebMethod ]
public DataSet getOrdersByCustomer(int customerNbr)
{
DataSet ds = new DataSet("OrderSet");
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT
OrderNumber,CustomerName,ExpectedShipDate
FROM OrderMaster WHERE CustomerNbr=" + customerNbr +
" ORDER BY OrderNumber";
oleDbDataAdapter1.Fill(ds,"Orders");
return ds;
}

Creating a J2EE Client for the .NET Orders Web Service
Next I began creating the J2EE client for the .NET Orders Web service. Most of the steps between WebLogic Workshop and Visual Studio .NET are the same, but the way they implement them is slightly different. WebLogic Workshop will also need a WSDL document in order to generate the client proxy, but the WSDL document must first be added to the lib directory before I can create a service control for the .NET Web service from the WSDL document. In the next code snippet I created an instance of the Service Control, created methods that mapped to the Web service methods, and then invoked the method.

private OrdersNETControl OrdersNETClient;

public Node getOrdersByCustomer(int customerNbr)
{
return (Node)
OrdersNETClient.getOrdersByCustomer(customerNbr);
}

Notice that WebLogic Workshop is expecting a Node to be returned from the .NET Orders Web service. Workshop has mapped the DataSet data type from .NET to a generic XML document Node in order to be able to extract the data values. This is still a little cumbersome to figure out. I had to hunt through the Control file that is generated by WebLogic Workshop to discover this.

OrdersNETControl.control
/** @editor-info:link source="OrdersNET.wsdl" autogen="true" */
import Weblogic.jws.control.ServiceControl;
/**
* @jws:location http-url="http://localhost/OrderRetrieval/Service1.asmx"
* @jws:wsdl file="#OrdersNETWsdl"
*/
public interface OrdersNETControl extends ServiceControl
{
public org.w3c.dom.Node getOrdersByEmployee
(java.lang.String EmployeeID);
...
}

Request and Response Code
Now that I have both a client and a Web service, let's look at what happens when I make a request to the Web service. With Web services, SOAP messages are sent back and forth either asynchronously or synchronously. Here I show only the portion of the SOAP message that pertains to the Web service method that I am invoking. I am calling the getOrdersByCustomer method and passing it a customerNbr parameter with a value of 200.

<getOrdersByCustomer xmlns="http://tempuri.org/">
<customerNbr>200</customerNbr>
</getOrdersByCustomer>
Fragment 9 - Request XML message

In response from the Web service I get an array of Orders that represent all orders with a customerNbr of 200.

<OrderSet xmlns="">
<Orders diffgr:id="Orders1" msdata:rowOrder="0">
<OrderNumber>2</OrderNumber>
<CustomerName>Set in Place</CustomerName>
<ExpectedShipDate>2002-10-02</ExpectedShipDate>
</Orders>
</OrderSet>

Considerations and Conclusions
Simple Web services interoperability with SOAP and WSDL can be proven with the following steps:

  • A J2EE client can invoke a .NET Web service
  • A J2EE client can use a .NET WSDL document to create a stub
  • A .NET client can invoke a J2EE Web service
  • A .NET client can use a J2EE WSDL document to create a stub

    There are additional steps that need to be taken by the industry to enhance interoperability between J2EE and .NET. First, support should be added for all XML Schema types. For example, the XML Schema type choice has no standard equivalent in the Java language. Second, support should be added for .NET data types that do not have an equivalent Java type. The ADO.NET type DataSet also has no equivalent Java type. In my experience, WebLogic Workshop translated a DataSet as a generic XML Node that is then parsed on the Java side to pull out the DataSet values. Third, support should be added to J2EE for the extensions that Microsoft has added to their SOAP implementation.

    WSDL is at the heart of service interoperability and, a common WSDL interface can increase reuse. Since WSDL defines the data types that a Web service is expecting, it enables interoperability with SOAP clients to the Web service. There are a number of tools available for both J2EE and .NET that can generate client-side proxies, which hides a layer of complexity from the developer. Other best practices include sticking with well-accepted standards (e.g., SOAP 1.2), keeping your data types as simple as possible, and providing XML Schema definitions for all of your data types.

    Web services can be written successfully in either .NET or J2EE. Simple interoperability between J2EE and .NET Web services is possible today, and continued improvements are coming from the interoperability standards bodies. Using common data types that can be easily serialized makes the developer's job easier. Learning a new language or a new programming paradigm might be necessary depending on your programming background.

    References

  • BEA Systems: www.bea.com
  • D.H. Brown Associates, Inc. "Web Services and Application Integration with J2EE and Microsoft .NET." December 2002.
  • Smith, David; Mark Driver; Chris Le Tocq; Whit Andrews, et al. "Weaving the Future: Microsoft's .NET Initiative," Gartner, September 20, 2001.
  • HP Developer's Central: www.hp.com/go/developers
  • HP Java products: www.hp.com/go/java
  • Karpinski, Richard. "Mission Interoperable: Rivals Aim to Link Web Services." InternetWeek, March 6, 2002.
  • Roman, Ed, and Chad Vawter. (June 2001) "J2EE vs. Microsoft.NET: A comparison of building XML-based Web services." The Middleware Company.
  • Microsoft Developer Network: http://msdn.microsoft.com
  • SOAPBuilders: www.soapbuilders.org.
  • Svoboda, Zdenek. (February 2002) "Developing Interoperable Web Services - Integrating Java and Microsoft .NET." Systinet.
  • Web Services Interoperability Organization: www.ws-i.org.
  • Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    IoT & Smart Cities Stories
    The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
    Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
    DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
    All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
    CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
    Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
    Cell networks have the advantage of long-range communications, reaching an estimated 90% of the world. But cell networks such as 2G, 3G and LTE consume lots of power and were designed for connecting people. They are not optimized for low- or battery-powered devices or for IoT applications with infrequently transmitted data. Cell IoT modules that support narrow-band IoT and 4G cell networks will enable cell connectivity, device management, and app enablement for low-power wide-area network IoT. B...
    The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
    SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
    When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...