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.


    @ThingsExpo Stories
    DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
    "Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of the 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to gre...
    The Internet of Things will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, demonstrated how to move beyond today's coding paradigm and shared the must-have mindsets for removing complexity from the develop...
    In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
    "Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
    Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
    Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
    "Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    "IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
    In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    "Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
    Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
    "MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
    "There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
    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...
    SYS-CON Events announced today that Telecom Reseller 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, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.