可重复使用程序代码 + 可重复使用模型 = 更高的生产力

可重复使用程序代码 + 可重复使用模型 = 更高的生产力

许多朋友最近见到我的时候经常出现的话题之一就是ECO,他们告诉我ECO非常地令人兴奋,他们都非常想要试试ECO,但是令他们困扰的是除了中文参考数据不多之外,就是想询问我ECO的可使用性。例如他们很怕ECO只能使用在BDS 2006的应用程序中,其他的应用,例如MSC#VB.NET,或是WinCE是否能够使用。我告诉他们未来ECO会支持WinCE,此外ECO是纯粹的.NET应用程序,其他的.NET语言或是应用程序当然也可以使用,甚至连Win32的应用程序都可以使用ECO提供的服务。怎么做? 那当然就是使用Web Services了。

让我简单地用一个Win32的应用程序范例来说明如何使用ECO服务吧。下图是我经常使用的一个范例业务逻辑模型,请各位注意的是,我甚至可以使用OCL来定义类的方法运算,这样一来,这个类图就更容易移植到其他平台,例如Java平台。

<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><span style="FONT-FAMILY: 全真中明體"><img style="WIDTH: 571px; HEIGHT: 401px" height="323" alt="" width="446" src="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOT1qnlbCTq9FutM8SZmXRwc2sefsmASnOTyi-n4tahpOFaCsxGmjM2Q37t5BDpLE4C6uRC9_4WehUeT6dBlpqczIZckgP48JBj7DxsvzXD8TlSqt4yy-5mI"></span><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 442.5pt; HEIGHT: 320.25pt" alt="" type="#_x0000_t75"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C03%5Cclip_image001.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOT1qnlbCTq9FutM8SZmXRwc2sefsmASnOTyi-n4tahpOFaCsxGmjM2Q37t5BDpLE4C6uRC9_4WehUeT6dBlpqczIZckgP48JBj7DxsvzXD8TlSqt4yy-5mI"></imagedata></shape>

<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 442.5pt; HEIGHT: 320.25pt" alt="" type="#_x0000_t75"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image001.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOT1qnlbCTq9FutM8SZmXRwc2sefsmASnOTyi-n4tahpOFaCsxGmjM2Q37t5BDpLE4C6uRC9_4WehUeT6dBlpqczIZckgP48JBj7DxsvzXD8TlSqt4yy-5mI"></imagedata></shape>

现在在BDS 2006中建立一个ECO ASP.NET Web Service应用程序(见下图):

<shape id="_x0000_i1026" style="WIDTH: 268.5pt; HEIGHT: 203.25pt" alt="" type="#_x0000_t75"><img style="WIDTH: 495px; HEIGHT: 359px" height="323" alt="" width="427" src="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOXPFxJogzxsokc27jFJDBxtSv8EdlCo_1eB3lxp2jxB3xp54J_IMhbhsCdUrO_eBy043UPtXI8hIZvT36qBsqPmi4m7vFSpATzqgjMm1UKPjRqoDvMb0Snk"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image002.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOXPFxJogzxsokc27jFJDBxtSv8EdlCo_1eB3lxp2jxB3xp54J_IMhbhsCdUrO_eBy043UPtXI8hIZvT36qBsqPmi4m7vFSpATzqgjMm1UKPjRqoDvMb0Snk"></imagedata></shape>

然后在产生的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

<shape id="_x0000_i1031" style="WIDTH: 327.75pt; HEIGHT: 232.5pt" alt="" type="#_x0000_t75"><img height="323" alt="" width="459" src="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOcZhj_hKVZ7B0qUoCdNVXgpiFjJg1QmaEyJsmeWxDbbZxqMy1i7uI7NWNXHtO0ZY_i7I90RfAbCHSWEax3YlMTwSh26Zi8_TYaPBlQXuYxEgqK_zmttZs2Y"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOcZhj_hKVZ7B0qUoCdNVXgpiFjJg1QmaEyJsmeWxDbbZxqMy1i7uI7NWNXHtO0ZY_i7I90RfAbCHSWEax3YlMTwSh26Zi8_TYaPBlQXuYxEgqK_zmttZs2Y"></imagedata></shape>

接着在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的应用程序调用、使用了。

<shape id="_x0000_i1032" style="WIDTH: 245.25pt; HEIGHT: 110.25pt" alt="" type="#_x0000_t75"><img alt="" src="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOUBhfWVnAHcAAgA4P4-TO3VykDixl806-uLhgaeb3Vd-c2qPaKktPkTWIKX-UQ_jKQjgDR9xMOugW_lAIYN0-t2poArHL1BYEE54bbl45jhn4ONPQCSkkkY"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image006.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOUBhfWVnAHcAAgA4P4-TO3VykDixl806-uLhgaeb3Vd-c2qPaKktPkTWIKX-UQ_jKQjgDR9xMOugW_lAIYN0-t2poArHL1BYEE54bbl45jhn4ONPQCSkkkY"></imagedata></shape>

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”那不是让开发人员的生产力更为提高吗?

<shape id="_x0000_i1027" style="WIDTH: 1in; HEIGHT: 51pt" alt="" type="#_x0000_t75" href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOcZhj_hKVZ7B0qUoCdNVXgpiFjJg1QmaEyJsmeWxDbbZxqMy1i7uI7NWNXHtO0ZY_i7I90RfAbCHSWEax3YlMTwSh26Zi8_TYaPBlQXuYxEgqK_zmttZs2Y" target="_blank" o:button="t"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image008.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOcZhj_hKVZ7B0swLk__QO1OxyFpUDzY8W247yNGq-LkYNg36lgY70UHpDpN0IbPx3RXgNG-4yR7iHeFpMgDsHqg"><font face="Times New Roman" size="3"></font></imagedata></shape>

<shape id="_x0000_i1028" style="WIDTH: 1in; HEIGHT: 52.5pt" alt="" type="#_x0000_t75" href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOT1qnlbCTq9FutM8SZmXRwc2sefsmASnOTyi-n4tahpOFaCsxGmjM2Q37t5BDpLE4C6uRC9_4WehUeT6dBlpqczIZckgP48JBj7DxsvzXD8TlSqt4yy-5mI" target="_blank" o:button="t"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image009.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOT1qnlbCTq9FCW9_0sU0b27VO3o9aeLdclMONDMhi4wGCjEiFIgCWHmxJSHx0RGo6AyLQahFIMuCPs1KXvY353o"><font face="Times New Roman"></font></imagedata></shape>

<shape id="_x0000_i1029" style="WIDTH: 1in; HEIGHT: 54.75pt" alt="" type="#_x0000_t75" href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOXPFxJogzxsokc27jFJDBxtSv8EdlCo_1eB3lxp2jxB3xp54J_IMhbhsCdUrO_eBy043UPtXI8hIZvT36qBsqPmi4m7vFSpATzqgjMm1UKPjRqoDvMb0Snk" target="_blank" o:button="t"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image010.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOXPFxJogzxso6yz6nnDeEn5XjLMInHCjU8hgFu3hAcWA2zTZaG-vm5bX4wde2pIPFwiTaOLKs9XvgHjfrTNfxbY"><font face="Times New Roman"></font></imagedata></shape>

<shape id="_x0000_i1030" style="WIDTH: 1in; HEIGHT: 32.25pt" alt="" type="#_x0000_t75" href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOUBhfWVnAHcAAgA4P4-TO3VykDixl806-uLhgaeb3Vd-c2qPaKktPkTWIKX-UQ_jKQjgDR9xMOugW_lAIYN0-t2poArHL1BYEE54bbl45jhn4ONPQCSkkkY" target="_blank" o:button="t"><imagedata src="file:///C:%5CDOCUME~1%5CADMINI~1.1F0%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image011.jpg" o:href="http://tkfiles.storage.msn.com/x1phiCZJPhsUYg-Rf0H_plhOUBhfWVnAHcAC5FP3PndK-CsLE-uE_hIjpzNs-1WfXHG3R3JuPWrwUBqoENra8d36ygHU2EVopXw3Qg3aCMbsmQ"><font face="Times New Roman"></font></imagedata></shape>

李维先生简体版博客由博文视点陈元玉编辑负责繁转简以及版式设计,如有疑问敬请您与编辑联系,联系方式:[email protected]

你可能感兴趣的:(F#,vb,Delphi,VB.NET,WinCE)