![]() |
|
URL of the article:
J2EE and .NET: Presentation Tier Interoperability
Using BEA WebLogic Server and .NET Client
by Binildas C. A.
Many enterprise projects use .NET based technology on the client side, where richness and performance are paramount considerations. This is then teamed up with a proven, stable, mature platform for server based enterprise applications, J2EE. While many enterprise projects have realized the power of this dynamite combination, several questions related to the interoperability considerations of using .NET with J2EE have gone unanswered. In this article, Binil Christudas attempts to shed light on this important, yet sparsely documented, area of interoperability considerations and some of the solutions available to work hassle-free with .NET and J2EE . The article converges at a point, and rightly so, to propose Web Services as a technology for attaining client side interoperability, and in that attempt addresses two important approaches: Top-Down and Bottom-Up. As proof of the proposed technology, practical demonstration of the two approaches, and the successful implementation of a solution, the author showcases a sample architecture based on BEA Weblogic Server and .NET C# client. Cruise along and pick up some nuggets for your next project that uses this potent combination
Introduction Java 2 Platform, Enterprise Edition (J2EE) is a mature middle tier technology that has become the norm for building production quality enterprise applications. Scalability, reliability, extensibility, security, etc. are a few of the main operating qualities which gives J2EE its edge over competing platforms. Even though it is comparatively straight forward to develop, deploy and maintain applications in the J2EE stack, many a times the J2EE components need to interoperate with other technologies. Recent trends in development has witnessed Java/J2EE's rising popularity in enterprise class server side application development from its historical stronghold in client side applets and applications. In assessing different solutions such as C and C++, and other object based programming languages like Delphi, Java/J2EE has been found the most stable and proven. Microsoft's Integrated Development Suite (IDS), composing its IDE, Visual Studio, along with a tight integration of programming languages like Visual Basic and Visual C++, has made this development environment the best for fast paced application development. ATLs and MFCs add to this suite. When evaluating for use in native applications that require speed and richness, these technologies are still preferred. Microsoft's .NET offerings that works across Windows 3.1 through Windows XP offer enhanced power to the developer desiring to implement an interoperable solution. In this article, we will combine the richness and performance of .NET with the stability and maturity of J2EE, shedding special focus on client side interoperability with examples deployed in BEA WebLogic Server 8.1 and .NET platform respectively. This article would be of interest to Technical Managers and Architects, Project Managers and Leads, and Developers. Since this paper is on interoperability, an exposure to multiple technologies (especially J2EE and .NET) is desirable. Requirements to Deploy and Run Examples Here is a list of requirements for deploying and running the examples in this article:
The scope of this article is limited to:
The following are not covered under the scope of this article:
Irrespective of advancements in the server side platform, an end user is interested in availing a service from the point of usability. A service, for example, can be accessed by a partner's system, a browser, or even a thick client built using another technology. It is when this service system becomes open that a series of aspects need to be considered: Interoperability Considerations In order for two parties in different technologies and platform to co-ordinate, both parties will need to agree on a set of protocol aspects. This is because, different platform stack will have its own representation of service and data, and we need to normalize or mediate between these heterogenous representations to enable the desperate parties to communicate. The following section lists out the major aspects to be considered:
Apart from the above micro aspects, there is the next level of considerations:
Interoperability is closely linked with distribution. If there is no distribution, there is no problem of interoperability. Although not an axiom, this reflects a normal case. Let us briefly discuss the available solutions:
Web Service is the best of available interoperability solutions today, unless performance or other key considerations warrant a binary solution. Since this article focuses on interoperability between a J2EE server and a .NET client, a discussion on the range of variations available within the Web Services programming model is beyond the scope of this article. Steps for Interoperability To ensure interoperability, we need to concentrate on the following aspects, amongst other items:
The primary specifications upon which Web Services are based is too open and broad that it opens up the scope for a lot of ambiguities once it gets implemented as a Web Service solution. To reduce these ambiguities and achieve interoperability, Web Service vendors formed a consortium called Web Service Interoperability Organization. This standards body drafted their first specification called the Basic Profile 1.0 (BP 1.0). This profile aims to bring about a set of conformance rules that clear up ambiguities in the above standards. Even though no one is required to adhere to BP, doing so will make interoperability less painful. There are primarily two approaches in integrating a .NET client and a J2EE server - Top-Down approach and Bottom-Up approach. Let us briefly explain the difference between these two:
Client applications that consume the Web Service need to understand the formats and valid values so as to process the service return types. Architecture for Presentation tier interoperability In this sample architecture, we will design for both the above scenarios. We will use the same application available in the examples folder in the Weblogic installation, and expend it for both the scenarios. We will have three methods in our service interface, as shown below: public interface Trader extends EJBObject{ TradeResult buy (String stockSymbol, int shares) throws RemoteException; TradeResult sell (String stockSymbol, int shares) throws RemoteException; String getAllProducts() throws RemoteException; } The notable point in this interface is that TradeResult is a complex type. When such a complex type is visible in the service interface, it eventually means that the client needs to understand this complex type when it binds to avail the service. Web Service standards are mature to the extent that this level of interoperability is possible in many cases. The third method does not have any visible complex type, but in fact the return type which is a simple string is going to be a flattened representation of a more complex type. The first two methods (buy and sell) are examples for the Top-Down approach, whereas we will build the third method (getAllProducts) in the Bottom-Up approach. The service will be implemented as a stateless session bean in the Weblogic J2EE platform. The client will be built in .NET using the C# programming language. ![]() Fig. 1: The Sample Architecture While the first two methods are straight forward, let us explore the rationale behind the third method. In fact, the third method is intended to return a collection of Product complex type. Perhaps, this type too is not that complex that we can return them similar to TradeResult as in the first two methods. But for demonstration of the concept, let us assume that the collection of Product complex type is not simple, and we have taken an architectural decision to flatten this collection as an XML string. For this, let us quickly list down the steps to be performed:
Deployment of the server component and exposing them as Web Service is straight forward (follow WebLogic Server Web Services programming examples referenced in the resources section for more details). One point which needs to be mentioned here is the conversion to XML, based on XSD. As usual, the data for Product types might be streamed from a database. Once the data and XSD are available, we normally need to use any of the available automatic methods to convert the data to XML format. Many Java XML products can map a field in the class to an element or attribute in the XML Schema. Sometimes the existing classes map to the correct schema without needing an intermediary. If this is the case, we can create mapping files for the existing classes, as this removes the step of taking the data from the existing Java classes into the Schema-based Java classes. Since the intention behind this article is to show the architectural building blocks for attaining interoperability and not demonstrate the various implementation mechanisms, this part is intentionally omitted by hard coding the XML structure with data in the server side implementation. In the client side we have two components, EJBClient and DataClient, both implemented in .NET. The EJBClient will avail the buy and sell services whereas the DataClient will access the getAllProducts service. For building the clients, we first need to generate client side stubs for the Web Service. The commands used are shown in Figure 2. ![]() Fig. 2: Generating Client side Stubs The commands will generate TraderService.cs (C#.NET files). Now, coding the EjbClient is straight forward. Executing EjbClient.exe, we can invoke Buy and Sell. ![]() Fig. 3: EJBClient in .NET The DataClient is designed to show the XML data retrieved from the server in a DataGrid control. This is done in just two lines of codes: products1.ReadXml(memStream); dataGrid.SetDataBinding(products1, "Product"); where products1 is a typed DataSet in .NET, and memStream is a MemoryStream type, which is an in-memory representation of the XML data. Even without generating a a typed DataSet, it is posible to bind the XML data using the above two lines of code and display it in the format shown in Figure 4. ![]() Fig. 4: Data Client in .NET A Typed DataSet is easily generated from the XSD, which helps especially when working with the DataSet to do type safe coding, using the command shown in Figure 5. ![]() Fig. 5: Generating typed DataSet Before building the server, do make necessary changes in the build.xml file, corresponding to the line: <property file="C:/bea/weblogic81/samples/server/examples/src/examples.properties"/> Summary The article described the integration of .NET technology in the client side to access Web Services implemented in BEA Weblogic platform. It walks the reader through architecting a solution for client side interoperability, following either the Top-Down approach or the Bottom-Up approach. The code examples demonstrate both J2EE based server implementation and .NET based client side bindings. The tail piece helps choose best the breed of solutions across technologies for different problems at hand and prompts the reader to follow the most appropriate architectural steps for attaining the required level of interoperability. Feedback on this article can be mailed to editors@jaxmag.com Resources Microsoft Web Service Development center BEA Dev2Dev Web Services center SOAPBuilders Interoperability for interoperability testing between SOAP implementations Web Services Description Language Specification SOAP specification UDDI HTTP 1.1 WS-I Basic Profile 1.0 Programming Weblogic Web Services Code Download for this article About the Author Binildas is a Senior Technical Architect at the Software Engineering Technology Labs (SET Labs) of Infosys. A graduate in Engineering and a post graduate in Systems Management, he is also a Sun Certified Programmer, Developer, Business Component Developer and Enterprise Architect, and a Microsoft Certified Professional. |
||
|