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
    Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
    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...
    In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
    With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
    Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
    The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
    No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
    Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
    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 ...
    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 ...
    DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
    @DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
    Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
    SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
    SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
    SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
    SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
    SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
    SYS-CON Events announced today that Nirmata will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
    SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...