麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

連接Corba和dotNet

2024-07-21 02:23:30
字體:
來源:轉載
供稿:網友

corba, 公用對象請求代理程序結構(common object request broker architecture)的首字母縮寫,在跨平臺和跨語言(如j2ee)的分布式(多層)系統通信中具有廣泛的應用,將corba連接到dotnet(在多層應用中,asp.net web services and .net remoting 是其主要應用方式)是不容易的。要連接這兩者,就需要一個能將dotnet的object描述成corba的object,以至于j2ee能使它們交互的方法,同樣,也能將corba的object描述成dotnet的object,讓dotnet的code能認識。換句話說,需要一些中間代碼能翻譯corba和dotnet framework之間的這些對象和方法調用。borland的janeva可以做到這一點。它簡化了corba或j2ee和dotnet之間的處理過程。

getting started
在開始之前,你需要有一個corba server,盡管有很多讀者都有而且在運行,但是還有很多沒有,所以,本文第一步就演示如何用c++創建一個簡單的corba server以練習和測試。要說明的是corba server同樣可以用java,delphi 以及其它語言編寫。第二步演示如何利用janeva連接這個server。

本例中的server是用borland c++builder 6 enterprise.創建的。如果沒有borland c++builder,你可以下載編譯過的server,這個server是基于一個個人議事日程的系統,用來安排電子會議。這個日程編排的細節對于本文來說不是很重要。重要的是如何你用janeva連接servere和client。

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.

一個corba服務能包含一個或多個corba對象,這些corba對象的接口聲明通常都存儲在idl文件中,當新建一個corba服務時,可以選擇一個存在的idl 文件或者新建一個空idl文件,然后加入corba對象的定義,本例中的idl如下:

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);

};

};



當點擊corba server的向導ok按鈕后,c++builder會創建一個新的工程,將form保存為.mainform.cpp,工程文件保存為bcb6corbaserver.bpr。在ide中將diarysrv.idl加入工程。當你編譯這個工程,c++builder會運行idl2cpp工具,產生4個基于idl定義的文件,即diarysrv_c.cpp and diarysrv_c.hh (for the stub classes,客戶端使用) , diarysrv_s.cpp and diarysrv_s.hh (for the skeleton classes服務端使用)。




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
分開skeleton和stub,要有一個能實際運行的diarysrv corba對象。可以使用向導。(see 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 will display the dialog shown in figure 3。

對于每一個idl文件,可以選擇所有接口,根據你選擇的是delegation model、data module并且是否需要在winmain中創建一個對象示例,向導會建議你輸入單元名、類名等。

點擊ok,ide會產生兩個文件icorbadiaryserver.cpp,icorbadiaryserver.h。這就是寫實際運行的corba server對象實現的地方。部分代碼:

#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::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.

注意檢查會議時間的代碼,如果會議持續時間超過一個小時,會拋出一個錯誤信息:"i don't like long meetings.",很顯然,這個異常純粹是演示corba異常,以及c#客戶端接受并回應這個錯誤。

在運行corba server之前,要保證visibroker在運行狀態。



build a corba client
我已經用c#builder創建了一個dotnet corba的客戶端,但理論上來說,任何dotnet語言都是可以的。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 可以讓microsoft .net framework 應用和j2ee/corba server 對象無縫結合并高效集成。c#builder的企業版和架構版都帶有janeva,你也可以到borland網站上下載(和其它dotnet 開發環境結合,詳細信息參見本文結尾)。




figure 6. add corba reference: janeva adds two items to the add references menu, letting you select j2ee or corba references as well as standard file or web references.

在免費注冊后,你可以得到一個用來測試的licence。但是,如果你要分發.net客戶端,則需要購買分發licence。

安裝完janeva,你就可以右擊c#builder中的工程文件,增加一個j2ee或corba引用(見圖6),沒有janeva,你只能增加普通接口或web reference。

因為本例是corba server,選擇增加corba引用,將會顯示一個對話框,可以選擇corba服務定義的idl文件。如圖7。

corba server應用發布“接口”定義是通過idl文件,支持corba客戶端應用的開發環境通常都支持將idl轉化為計算機語言,如c++、java,然而對于dotnet客戶端,必須要將idl轉化為dotnet語言,如vb.net 或c#,idl-to-c#(idl2cs)是borland janeva最受歡迎的特征。





figure 7. adding a corba reference: browse to the location of the diarysrv.idl file to add the reference.

注意,盡管你導入了corba server的定義,但是你還沒有指明如何連接它。

添加了idl文件后,janeva導入并編譯idl文件,產生一個相應的cs文件(diarysvr.cs)。




"figure 8. manual janeva compile: if you need to alter an idl file after adding it, right-click the file in project manager and select janeva compile from the context menu.

如果將來你要改變idl文件,可以在工程管理器中右擊idl文件(如圖8)選擇重新編譯。

要使用diarysrv.cs,在using中增加corba命名空間和產生的diarysrv命名空間。

using system;

using system.drawing;

using system.collections;

using system.componentmodel;

using system.windows.forms;

using system.data;



using corba;

using diarysrv;



在winform的構造函數中,創建orb(對象請求代理)的實例,來連接客戶端和服務端。要做到這樣,利用vbroker代理端口和14000參數(visibroker默認端口-譯者注)調用corba.orb.init即可。

我使用的是默認的14000端口,你可以使用另外的端口,端口的配置相信信息請參見corba orb的文檔。

string[] args = new string[]

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

orb = corba.orb.init(args);

calling the corba server
配置完客戶端程序后,可以利用一個按鈕來創建corba diarysrv對象的實例。然后調用meeting方法。

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");

}

}

對照代碼,可以發現:

首先,必須通過正確的名字(在corba服務端創建corba diary 服務對象時指定的,本例中為icorbadiaryserverobject)調用綁定方法。

綁定完corba服務器端對象后,才能調用meeting方法。但是不要沒有檢索date和time,并構造特殊的diarysrv.datetime(idl文件和corba服務端實現的類型) 對象。




figure 9. c#builder corba client: the figure shows the main window for the completed corba client running.

代碼還包含了4個label和textbox控件,用來讓最終用戶輸入meeting方法需要的名稱,日期,時間,持續時間等信息。在運行階段,應用程序效果如圖9

注意,持續時間設定為61分鐘,僅僅是讓corba客戶端拋出異常(如圖10)。




figure 10. corba exception: a messagebox display of an exception received by the c#builder corba client.

只有將時間限制在60分鐘內。就可以安全的增加會議安排到議事日程中。

你在這里所看到的就是janeva作為所謂的在corba server和dotnetclient間的企業應用 集成(eai)層。這項技術的主要優點就是你可以不需重寫或修改已經存在的corba服務就可以連接dotnet應用。



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

第一次翻譯,請指正。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲一区 国产精品 | 久久久久夜色精品国产老牛91 | 国产精品一区在线看 | 久久亚洲网| 成人免费一区二区三区 | 激情综合在线观看 | 免费看成人av | 一本一本久久a久久精品综合小说 | 中文字幕在线播放不卡 | 国产精品免费小视频 | 欧日韩在线 | 韩国一级免费视频 | 国产成人av在线播放 | 精品午夜影院 | 欧美日韩亚洲在线观看 | 精品国产一区二区亚洲人成毛片 | 久久久久久中文字幕 | 欧美黄色免费视频 | 色啪综合 | 蜜桃久久一区二区三区 | 久久久精品视频免费看 | 深夜激情视频 | 91成人影库 | 亚洲一区中文字幕 | 成年免费大片黄在线观看岛国 | 性生活视频网站 | 久久精品亚洲精品国产欧美kt∨ | 成年人黄色免费电影 | 亚洲精品永久视频 | 国产成人精品区一区二区不卡 | 在线播放亚洲精品 | 高清在线观看av | 色交视频 | 国产精品久久久久久久久久久久久久久久 | 成人毛片在线 | 免费a级毛片永久免费 | www.99热精品 | 久久精品一区视频 | 成年人黄色免费电影 | 久草视频福利在线观看 | 久久艹精品 |