Connect CORBA and DOTNET
HoWcanido
Original http://www.devx.com/interop/Article/19916/0/page/1
CORBA, common object requesting agent architecture, a wide range of applications in cross-platform and cross-language (such as J2EE) distributed (multi-layer) system communication, connect CORBA to DOTNET (In multi-layer applications, ASP.NET Web Services and .Net Remoting is not easy. To connect to these, you need a way to describe the DOTNET's Object to CORBA's Object, so that J2EE can make them interact, similarly, you can also describe CORBA's Object's Object, let DOTNET's Code can know . In other words, some intermediate code can translate these objects and method calls between CORBA and DOTNET Framework. This can be done by Janeva, Borland. It simplifies the process of processing between CORBA or J2EE and DOTNET.
Getting start
Before you start, you need a CORBA Server, although there are many readers and run, but there are many not, so this article demonstrates how to create a simple CORBA Server with C to practice and test. To explain that Corba Server can also be written in Java, Delphi, and other languages. The second step show how to connect this Server using Janeva.
The server in this example is created with Borland C Builder 6 Enterprise. If there is no Borland C Builder, you can download the compiled server, this Server is based on a personal agenda system to arrange an electronic conference. This schedule arrangement is not important for this article. What is important is how you connect Servere and Client with Janeva.
Build a CORBA Server
To Build The Corba Server, Start C Builder, Click The File | New Menu, SELECT Other and Go To The Multitier Tab of The Object Repository (See Figure 1).
Figure 1. C Builder Object Repository: The Object Repository Contains a list of the items available
Figure 2. CORBA Server Wizard: You Use this Wizard to Specify Project Options for a New Corba Server Project.
A number of icons appear in the dialog related to CORBA. To start a new CORBA server project from scratch, double-click on the CORBA Server icon, which will display the CORBA Server Wizard so you can specify the options for the new project (see Figure 2).
You can choose to create a Console Application (with or without using Borland's Visual Component Library) or a Windows Application. For this project, select the Windows Application option, because it's convenient to have the server display some visual (debug) information during development. A CORBA service can contain one or more CORBA objects that are usually stored in the IDL file. When new CORBA services are new, you can select an idl file or create a new empty IDL file, then join CORBA The definition of the object, the IDL in this example is as follows:
Module DiarySRV
{
Struct datetime {
Long Date; // Example: 20030929
Long Time; // EXAMPLE: 1200
}
Interface icorbadiaryServer
{
Exception MeetingImpossible
{
String.
}
Void Meeting (In Wstring Names, In LONG DURATION)
METINGIMPOSIBLE;
}
}
When you click the Corba Server's Wizard OK button, C Builder creates a new project, saving the Form as .mainform.cpp, the project file is saved as BCB6CORBASERVER.BPR. DiarySRV.IDL is joined in the IDE. When you compile this project, C Builder runs the IDL2CPP tool, generates 4 IDL-based files, namedrv_c.cpp and diarysrv_c.hh (for the stub classes, client use), DiarySrv_s.cpp and diarysrv_s.hh (for the Skeleton Classes server).
Figure 3. CORBA Object Implementation Wizard: You Use this Wizard To Specify The Idl File, Select Interface Names, The Delegation Model, And Other Properties.
CORBA Object Implementation
Separate Skeleton and Stub, there is a DiarySRV CORBA object that can actually run. You can use the wizard. (See Figure 1 for the icon in the object repository). Click File | Newothers, Go to the Multitier Tab, And Double-Click ON The Corba Object Implementation Icon, Which Will Display The Dialog Shown in Figure 3.
For each IDL file, you can choose all interfaces, depending on the Decation Model, Data Module and whether you need to create an object sample in WinMain, you will suggest you into the unit name, class name, etc.
Click OK, IDE will generate two file icorbadiaryserver.cpp, icorbadiaryserver.h. This is where the Corba Server object that is implemented is implemented. Part of code: #pragma HDRSTOP
#include
#include "icorbadiaryserverseerver.h"
#include "mainform.h"
/ / -------------------------------------------------------------------------------------------- ----
#pragma package (smart_init)
IcorbadiaryServerImpl :: icorbadiaryServerImpl
Const char * Object_name):
_SK_DiarySRV :: _ SK_ICORBADIARYSERVER (Object_name)
{
IF (Form1)
FORM1-> CAPTION =
"IcorbadiaryServer Up and Running ...";
}
Void icorbadiaryserverImpl :: meeting
Const Corba :: wchar * _names,
Const Diarysrv :: DateTime &_Daytime, CORBA :: Long
_Duration)
{
IF (Form1)
Form1-> Memo1-> lines-> add (
"Meeting with" Ansistring (_Names));
IF (_duration> 60)
Throw
Diarysrv :: icorbadiaryserver :: MeetingImpossible
"I don't like long meetings ...");
}
Figure 4 shows the running application.
Figure 4. The Running Corba Server: here's a screenshot of the completed corba server.
Pay attention to the code for the meeting time. If the meeting lasts for more than an hour, an error message will throw an error message: "I don't like long meetings." And respond to this error.
Before running CORBA Server, ensure that Visibroker is running.
Build a Corba Client
I have created a DOTNET CORBA client with C # Builder, but in theory, any DotNet language is ok. Start C # Builder Enterprise or Architect, and create a new c # Application. In The New Application Dialog You CAN Specify The Name As Well As The Location of The New Project (See Figure 5).
Borland Janeva 1.0
Borland Janeva allows Microsoft .NET Framework applications and J2EE / CORBA Server objects seamlessly combined with efficient integration. C # Builder's Enterprise Edition and Architecture Edition has Janeva, you can also download on the Borland website (combined with other DOTNET development environments, see the end of this article).
Figure 6. Add Corba Reference: Janeva Adds Two items to the add refretences menu, Letting you select J2ee or corba references As Well AS Standard file or Web References. After free registration, you can get a license for testing. However, if you want to distribute the .NET client, you will need to purchase distribute Licence.
After installing Janeva, you can right-click the project file in C # Builder, add a J2EE or CORBA reference (see Figure 6), no Janeva, you can only add ordinary interface or web reference.
Because this example is CORBA Server, select Add a CORBA reference will display a dialog, you can select the IDL file defined by the CORBA service. Figure 7.
CORBA Server Application Publishing "Interface" Definition is through the IDL file, the development environment that supports CORBA client applications typically supports converting IDL into computer languages, such as C , Java, however for DOTNET clients, you must convert IDL to DotNet language For VB.NET or C #, IDL-TO-C # (IDL2CS) is the most popular feature of Borland Janeva.
Figure 7. adding a corba reference: browse to the location of the diarysrv.idl file to add the reason.
Note that although you imported the definition of CORBA Server, you haven't specified how to connect it.
After adding the IDL file, Janeva imported and compiles the IDL file to generate a corresponding CS file (DiaRysvr.cs).
"Figure 8. Manual Janeva Compile: if you need to alter an idl file after address.
If you want to change the IDL file in the future, you can right-click the IDL file (Figure 8) in the Project Manager (Figure 8) to select recompilation.
To use diarysrv.cs, add CORBA namespaces and generated DiarySRV namespaces in USING.
Using system;
Using system.drawing;
Using system.collections;
Using system.componentmodel;
Using system.windows.forms;
Using system.data;
USING CORBA;
Using diarysrv;
In the WinForm constructor, an instance of an ORB (Object Request Agent) is created to connect to the client and the server. To do this, use the Vbroker proxy port and 14000 parameters (Visibroker Default Port - Translator Note) to call corba.orb.init.
I am using the default 14000 port, you can use additional ports, the port configured to believe, see the documentation of Corba ORB.
String [] args = new string []
{"-vbroker.Agent.port", "14000"}; orb = corba.orb.init (args);
Calling the corba server
Once the client program is configured, you can use a button to create an instance of the CORBA DiarySRV object. Then call the Meeting method.
Private void button1_click (Object Sender,
System.Eventargs E)
{
Try
{
Mycorbadiaryserver =
IcorbadiaryServerHelper.bind
IcorbadiaryServerObject ");
Diarysrv.datetime mydatetime = new
Diarysrv.datetime ();
Mydatetime.date =
Convert.TOINT32 (TextBox2.text);
Mydatetime.time =
Convert.TOINT32 (TextBox3.text);
MycorbadiaryServer.meeting (TextBox1.text,
MyDateTime, Convert.Toint32 (TextBox4.text);
}
Catch
(DiarySrv.icorbadiaryServerns.meetingImpossible
EX)
{
Messagebox.show (Ex.reason, "CORBA Exception");
}
Catch (Exception EX)
{
Messagebox.show (ex.Message, "Error");
}
}
Control code, you can find:
First, you must call the binding method to call the iCORBADIARYSERVEROBJECT in this case by creating a CORBA DiRy service object when Corba DITIARY service object is created.
After binding the CORBA server-side object, you can call the Meeting method. But don't retrieve Date and Time, and construct a special DiaRySRV.DateTime (IDL file, and CORBA server implementation type) object.
Figure 9. C # Builder Corba Client: The Figure shows The main window for the completed corba client running.
The code also contains four Label and TextBox controls to allow the end user to enter the name, date, time, duration of the Meeting method. In the stage of operation, the application effect is shown in Figure 9
Note that the duration is set to 61 minutes, just let the CORBA client throw an exception (Figure 10).
Figure 10. Corba Exception: a messagebox display of an exception receivers by the c # Builder Corba Client.
Only the time limit is within 60 minutes. The meeting can be arranged to arrange the meeting to schedule.
What you see here is Janeva as a so-called enterprise application integration (EAI) layer between Corba Server and DotNetClient. The main advantage of this technology is that you can connect DOTNET applications without rewriting or modifying the existing CORBA service.
-----------------------------------
For the first time, please correct it.