Borland發布了C Builder 6以及Delphi 6的第二個補丁。這是一個對Delphi 6來說,非常重要的一個補丁,不但修正了Delphi 6中一些問題,還在很大程度上增強了Delphi 6的功能,特別是在SOAP/Web Service開發方面。
上圖為新的新建Web Service頁,與打補丁之前相比(見《DELPHI 6 搶先研究 -- BizSnap/SOAP/WebService 之一 -- 一個 Hello world! 的例子》等), 除了將圖標全部換掉(現在與C Builder 6相同)以外,還增加了一項: SOAP Server Interface向導,這是一個新建SOAP服務端接口的向導,在前面的介紹中, 新建一個SOAP服務端接口需要寫不少代碼,有了這個向導就可以省很多事。
因為有了SOAP Server Interface向導,在新建一個Web Service應用時會自動詢問是否產生一個服務端接口,如上圖。除了是要用SOAP進行多層應用開發以外,都是要新建接口的。新建服務端接口的向導對話框如下圖。
仿照《DELPHI 6 搶先研究 -- BizSnap/SOAP/WebService 之一 -- 一個 Hello world! 的例子》的例子,新建一個SoapHello接口,在Service Name中輸入SoapHello,確定后即可產生兩個單元:SoapHelloIntf.pas和SoapHelloImpl.pas,分別為此接口的接口定義和接口實現單元。
以下為SoapHelloIntf.pas單元的內容:
{ Invokable interface ISoapHello }unit SoapHelloIntf;interfaceuses InvokeRegistry, Types, XSBuiltIns;type { Invokable interfaces must derive from IInvokable } ISoapHello = interface(IInvokable) [''''{3A9E6BD6-F128-40AD-B9F1-FB254C463CCC}''''] { Methods of Invokable interface must not use the default } { calling convention; stdcall is recommended } end;implementationinitialization { Invokable interfaces must be registered } InvRegistry.RegisterInterface(TypeInfo(ISoapHello));end.
以下為SoapHelloImpl.pas單元的內容:
{ Invokable implementation File for TSoapHello which implements ISoapHello }unit SoapHelloImpl;interfaceuses InvokeRegistry, Types, XSBuiltIns, SoapHelloIntf;type { TSoapHello } TSoapHello = class(TInvokableClass, ISoapHello) public end;implementationinitialization { Invokable classes must be registered } InvRegistry.RegisterInvokableClass(TSoapHello);end.
然后,只需要在這兩個單元中加入所需的接口方法的定義和實現,即可完成一個服務端接口,較原來方便很多。 這還只是表面的變化,在本章第一個例子中,如果輸入 http://localhost/soap/soaptest.dll 是看不到什么東西的,必須輸入 http://localhost/soap/soaptest.dll/wsdl 才能看到所有接口的WSDL列表。但是在打了Delphi 6補丁2后重新編譯此例子程序,可以看到 http://localhost/soap/soaptest.dll 顯示一個漂亮的頁面,與用Visual Studio.net進行SOAP開發類似。而 http://localhost/soap/soaptest.dll/wsdl 頁面也與原來的不同。然而這還不是最主要的改變,看看 http://localhost/soap/soaptest.dll/wsdl/IsoapHello 頁面,與前面的WSDL相比之下有了一些小小的改變,而這才是最重要的,這一改進終于讓用Delphi 6開發的Web Service應用程序可以被Visual Studio.net開發的客戶端程序調用了!下面就是新的WSDL文件:
<?xml version="1.0"?><definitions xmlns="> </output> </operation> </binding> <service name="IHelloservice">