Delphi 6 Update 2 的意義

來源:互聯網
上載者:User

DELPHI 6.02 搶先研究 -- BizSnap/SOAP/WebService 之四

-- 補丁2#的意義

    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;

interface

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

implementation

initialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(ISoapHello));

end.

    以下為SoapHelloImpl.pas單元的內容:

{ Invokable implementation File for TSoapHello which implements ISoapHello }

unit SoapHelloImpl;

interface

uses InvokeRegistry, Types, XSBuiltIns, SoapHelloIntf;

type

{ TSoapHello }
TSoapHello = class(TInvokableClass, ISoapHello)
public
end;

implementation

initialization
{ 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="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" name="IHelloservice"
targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<message name="GetHelloRequest">
<part name="aID" type="xs:int"/>
</message>
<message name="GetHelloResponse">
<part name="return" type="xs:string"/>
</message>
<portType name="ISoapHello">
<operation name="GetHello">
<input message="tns:GetHelloRequest"/>
<output message="tns:GetHelloResponse"/>
</operation>
</portType>
<binding name="IHellobinding" type="tns:IHello">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetHello">
<soap:operation soapAction="urn:HelloIntf-IHello#GetHello" style="rpc"/>
<input>
<soap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:HelloIntf-IHello"/>
</input>
<output>
<soap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:HelloIntf-IHello"/>
</output>
</operation>
</binding>
<service name="IHelloservice">
<port name="IHelloPort" binding="tns:IHellobinding">
<soap:address location="http://localhost:1024/WSDemo1.WSDemo1/soap/IHello"/>
</port>
</service>
</definitions>

    新的WSDL Importer也有很大的變化。顯示了新的WSDL Importer嚮導,較原來的(如《DELPHI 6 搶先研究 -- BizSnap/SOAP/WebService 之一 -- 一個 Hello world! 的例子》)要漂亮很多,當然這也還只是表面,單擊"下一步",如果成功匯入介面,即可立即看到產生的介面檔案內容,如按"完成"就可以產生介面檔案(注意:因為產生的介面檔案名稱預設為介面名,但Delphi有一個限制就是單元名不可以與對象重名,所以必須改名後才能儲存)。

    當然,WSDL Importer的改進也不只是這些表面的東西,最重要的改進也是它已經可以方便地匯入用Visual Studio.net寫的Web Service程式產生的WSDL,並可以順利訪問其介面。
    最後值得一提的是: C++ Builder 6 的 SOAP 部分與 Delphi 6 的補丁2#相同,如果在未打補丁2#的 Delphi 6 的同一台機器上裝 C++ Builder 6 將導致 Delphi 6 的 SOAP 部分不可用,解決辦法就是打 Delphi 6 的補丁2#。

[Mental Studio]猛禽 Mar.20-02

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.