万企互联-专注高端网站建设
扫描关注万企互联微信公众账号

扫一扫微信二维码

Delphi 6 Update 2 的意义

程序设计2012/2/14 1471

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="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">

文章分类
程序设计
打开微信,点击底部的“发现”,使用“扫一扫”即可将网页分享至朋友圈。
万企互联 咸阳网站建设 咸阳微信营销 IDC主机测评 IP地址查询 万企工具 四六互联 四六技术网 超越彼岸BEYOND 六佰号 秦川云 秦川云影院