Connecting CORBA and Dotnet

Source: Internet
Author: User
Tags definition contains datetime dotnet connect web services client
CORBA, the acronym for the Common Object Request Broker Architecture (Common object Requests Broker architecture), is widely used in distributed (multi-tier) system communications across platforms and cross-language (e.g. Java ee). It is not easy to connect CORBA to dotnet (asp.net Web services and. NET Remoting are its primary applications in multi-tier applications). To connect both, you need a method that describes the object of dotnet as CORBA, so that the way that Java EE can interact with it, it can also describe the object of CORBA as Dotnet object, so that dotnet's code can be understood. In other words, some intermediate code is needed to translate these objects and method calls between CORBA and the dotnet framework. Borland's Janeva can do this. It simplifies the process of processing between CORBA or Java EE and dotnet.

Getting Started
Before you start, you need to have a CORBA server, although there are many readers and running, but there are many not, so the first step in this article demonstrates how to create a simple CORBA server in C + + to practice and test. The explanation is that CORBA server can also be written in Java,delphi and other languages. The second step demonstrates how to use Janeva to connect to this server.

In this case, the server is created with Borland C++builder 6 Enterprise. If you don't have Borland c++builder, you can download the compiled server, which is based on a personal agenda system for arranging electronic meetings. The details of this schedule are not very important for this article. It's important 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 (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 would display the CORBA serv Er Wizard so can specify the options for the new project (Figure 2).

Can choose to create a Console application (with or without using Borland ' s Visual Component Library) or a Windows App Lication. For this project, select the Windows application option, because it's convenient to have the server display some visual (d Ebug) information during development.

A CORBA service can contain one or more CORBA objects, and the interface declarations of these CORBA objects are usually stored in the IDL file, when a new CORBA service is created, an existing IDL file can be selected or a new empty IDL file is created, and then the definition of the CORBA object is added. 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 Reason;

};



void meeting (in Wstring Names, in DateTime daytime, in long Duration)

Raises (meetingimpossible);

};

};



When you click on the CORBA Server's Wizard OK button, C++builder creates a new project, saves the form as. MainForm.cpp, and the project file is saved as a BCB6CORBASERVER.BPR. Add Diarysrv.idl to the project in the IDE. When you compile this project, C++builder will run the Idl2cpp tool, generating 4 files based on IDL definitions, namely Diarysrv_c.cpp and Diarysrv_c.hh (for the stub classes, client use), Diarysrv_s.cpp and DIARYSRV_S.HH (for the Skeleton classes service-side use).




Figure 3. CORBA Object Implementation Wizard:you Use this Wizard to specify the IDL file, select interface names, the delegation mo Del, and other properties.

CORBA Object Implementation
Separate skeleton and stubs to have a diarysrv CORBA object that can actually run. You can use the wizard. (Figure 1 for the icon in the Object Repository). Click File | Newother, go to the Multitier tab, and double-click on the CORBA Object implementation icon, which'll display the dialog shown in Figure 3.

For each IDL file, you can select all interfaces, and depending on whether you choose Delegation Model, data module, or if you need to create an object sample in WinMain, the wizard will suggest you enter the cell name, class name, and so on.

Click Ok,ide will produce two file icorbadiaryserver.cpp,icorbadiaryserver.h. This is where the actual running CORBA server object implementation is written. Part of the code:

#pragma hdrstop



#include <corba.h>

#include "ICorbaDiaryServerServer.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::D atetime& _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.

Note that the code that checks the meeting time, if the meeting lasts longer than one hours, throws an error message: "I don ' t like long meetings.", obviously, this exception is purely demo CORBA exception, and the C # client accepts and responds to this error.

Before running CORBA server, make sure that the Visibroker is running.



Build a CORBA Client
I've created a dotnet CORBA client with C#builder, but theoretically, 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 as as the location of the new project (the 5).





Borland Janeva 1.0
Borland Janeva enables seamless and efficient integration of Microsoft. NET Framework applications and J2ee/corba server objects. C#builder's Enterprise and Architecture editions are Janeva, and you can also download them to Borland Web site (in conjunction with other dotnet development environments, see the end of this article for more information).




Figure 6. Add CORBA Reference:janeva adds two items to the Add References menu, letting your select Java or CORBA References as As standard file or Web references.

After registering for free, you can get a licence for testing. But if you want to distribute it. NET client, you need to purchase a distribution licence.

After installing Janeva, you can right-click the project file in C#builder, add a Java EE or CORBA reference (see Figure 6), without Janeva, you can only add the normal interface or Web reference.

Because this example is a CORBA server, choosing to add a CORBA reference will display a dialog box that allows you to select the IDL file for the CORBA service definition. As shown in Figure 7.

CORBA Server Application Publishing interface definition is through IDL files, development environments that support CORBA client applications typically support the translation of IDL into computer languages, such as C + +, Java, but for dotnet clients, IDL must be converted to dotnet language, such as 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 Reference.

Note that although you have imported the definition of CORBA server, you have not yet indicated how to connect it.

After the IDL file has been added, Janeva imports and compiles the IDL file to produce a corresponding CS file (DiarySvr.cs).




"Figure 8. Manual Janeva compile:if you need to alter a IDL file after adding it, right-click the file in Project Manager and Selec T Janeva Compile from the context menu.

If you want to change the IDL file in the future, you can choose to recompile in the project manager by right-clicking the IDL file (Figure 8).

To use DiarySrv.cs, add the CORBA namespace and the resulting Diarysrv namespace in the 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, create an instance of the Orb (object request proxy) to connect the client and the server. To do so, use the Vbroker proxy port and the 14000 parameter (visibroker default port-translator) to invoke CORBA.ORB.Init.

I am using the default 14000 port, you can use another port, the configuration of the Port trust information see the documentation for the CORBA Orb.

string[] args = new string[]

{"-vbroker.agent.port", "14000"};

Orb = CORBA. Orb. Init (args);

Calling the CORBA Server
After you configure the client program, 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, the binding method must be invoked through the correct name (specified when the CORBA Diary service object is created on the CORBA server, in this case icorbadiaryserverobject).

You cannot invoke the meeting method until you have finished binding the CORBA server-side object. However, do not retrieve date and time and construct a special diarysrv.datetime (IDL file and type of CORBA server implementation) object.




Figure 9. C#builder CORBA client:the Figure shows the main window for the completed CORBA Client running.

The code also contains 4 label and TextBox controls that allow end users to enter information such as the name, date, time, duration, and so on that the meeting method requires. In the run phase, the application effect is shown in Figure 9

Note that the duration is set to 61 minutes, just to have the CORBA client throw an exception (Figure 10).




Figure 10. CORBA exception:a MessageBox Display of a Exception received by the C#builder CORBA client.

Only limit your time to 60 minutes. The meeting can be safely added to the agenda.

What you see here is Janeva as the so-called Enterprise Application integration (EAI) layer between CORBA server and dotnetclient. The main advantage of this technique is that you can connect dotnet applications without having to rewrite or modify existing CORBA services.



―――――――――――――――――――――――――――――――――――

For the first translation, please correct me.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.