可重複使用程序代碼 + 可重複使用模型 = 更高的生產力

可重複使用程序代碼 + 可重複使用模型 = 更高的生產力

許多朋友最近見到我的時候經常出現的話題之一就是ECO,他們告訴我ECO非常地令人興奮,他們都非常想要試試ECO,但是令他們困擾的是除了中文參考數據不多之外,就是想詢問我ECO的可使用性。例如他們很怕ECO只能使用在BDS 2006的應用程序中,其他的應用,例如MSC#VB.NET,或是WinCE是否能夠使用。我告訴他們未來ECO會支持WinCE,此外ECO是純粹的.NET應用程序,其他的.NET語言或是應用程序當然也可以使用,甚至連Win32的應用程序都可以使用ECO提供的服務。怎麼做? 那當然就是使用Web Services了。

讓我簡單地用一個Win32的應用程序範例來說明如何使用ECO服務吧。下圖是我經常使用的一個範例業務邏輯模型,請各位注意的是,我甚至可以使用OCL來定義類的方法運算,這樣一來,這個類圖就更容易移植到其他平臺,例如Java平臺。

 

現在在BDS 2006中建立一個ECO ASP.NET Web Service應用程序(見下圖):

 

然後在產生的Web Services中(*.asmx文件)加入如下的Web Services方法:

[WebMethod]

function GetDevCoSeminarCount : Integer;

[WebMethod]

function GetDevCoSeminar : TDevCoSeminarList;

然後實現如下:

function TDevCoSeminarService.GetDevCoSeminar: TDevCoSeminarList;

const

  SEMINARCOUNT = 'DevCoSeminar.allInstances';

var

  OclService: IOclService;

  ResultElement: IElement;

begin

  OclService := EcoSpace.GetEcoService(typeof(IOclService)) as IOclService;

  ResultElement := OclService.EvaluateAndSubscribe(nil, SEMINARCOUNT, nil, nil);

  Result := CreateDevCoSeminarDTOs(ResultElement);

  DoneWithEcoSpace;

end;

 

function TDevCoSeminarService.CreateDevCoSeminarDTOs(

  ResultElement: IElement): TDevCoSeminarList;

var

  al : TDevCoSeminarList;

  anElement : IElement;

  aSeminar : DevCoSeminar;

  aDTO : TDevCoSeminar;

  iIndex : Integer;

begin

  SetLength(al, ResultElement.GetAsCollection.Count);

  iIndex := 0;

  for anElement in  ResultElement.GetAsCollection do

  begin

    aSeminar := anElement.AsObject as DevCoSeminar;

    aDTO.FName := aSeminar.Name;

    aDTO.FLocation := aSeminar.Location;

    aDTO.FSrDate := aSeminar.srDate.ToLongDateString;

    aDTO.FMaxCount := aSeminar.MaxCount;

    al[iIndex] := aDTO;

    Inc(iIndex);

  end;

  Result := al;

end;

接着編譯這個ECO Web Service應用程序,等待稍後的Win32客戶端應用程序調用,使用它提供的服務。

現在我再使用Delphi 7(或是BDS 2006中的Delphi For Win32)建立一個VCL Form應用程序,啓動WSDL Importer嚮導輸入剛纔開發的ECO Web Service應用程序的WSDL

 

接着在VCL窗體中實現如下的程序代碼來調用ECO Web Service應用程序:

procedure TForm1.Button1Click(Sender: TObject);

var

  aWS : TDevCoSeminarServiceSoap;

  wsResult : ArrayOfTDevCoSeminar;

  icount : Integer;

  aSeminar : TDevCoSeminar;

  sData : String;

begin

  aWS := GetTDevCoSeminarServiceSoap;

  edtCount.Text := IntTostr(aWS.GetDevCoSeminarCount);

  wsResult := aWS.GetDevCoSeminar;

  for iCount := Low(wsResult) to High(wsResult) do

  begin

    aSeminar := wsResult[iCount];

    sData := aSeminar.FName + ':' + aSeminar.FSrDate + ':' +

             aSeminar.FLocation + ':' + IntToStr(aSeminar.FMaxCount);

    ListBox1.Items.Add(sData);

  end;

end;

上面的TDevCoSeminarServiceSoap就是WSDL Importer嚮導封裝遠程Web Service應用程序的wrapper類。編譯並且執行這個Delphi 7Web Service客戶端應用程序,我們可以看到如下圖所示的執行結果,ECO的服務果然成功地被Delphi Win32的應用程序調用、使用了。

 

Yah, 我們在Windows 32下使用Delphi 7就完成了使用由.NET ECO/MDA/DDA實現的業務邏輯服務。ECO強大的可重複使用性再次令人印象深刻。

瞭解了上面的討論之後,各位有使用VS.NET的朋友當然也可以使用VS.NETVB.NET或是MS C#來使用ECO提供的服務了。

使用了ECO技術,ECO不但是“Write code once and Run everywhere”,甚至是“Model 你的business logic once and reuse everywhere”,“Reuse Code + Reuse Model”那不是讓開發人員的生產力更爲提高嗎? 

 

 

 

 
 
 
 

 

 

 

 

李維先生簡體版博客由博文視點陳元玉編輯負責繁轉簡以及版式設計,如有疑問敬請您與編輯聯繫,聯繫方式:[email protected]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章