首页 > delphi > Delphi7下开发Webservice以及部署问题

Delphi7下开发Webservice以及部署问题

2008年4月24日 发表评论 阅读评论

Delphi7支持五种部署方式来开发Webservice,分别介绍:

Isapi是在IIS下运行;

CGI是可以在IISapache下运行;我自己只在iis下部署了,没试apache

Apache 1.x需要部署到apache1的版本下;

Apache2.x需要部署到apache2

Debugger 是可以在方便Delphi中继承调试的;

以上可以在编写完业务代码后,再根据部署环境的不同,可以单独建立项目来实现,在开发时完全一样。

以下是我在应用碰到的问题和解决方式:

一、首先 我以Isapi部署项目,在Xp Professor下能够运行,但不稳定,经常出现Xml不是正确的格式。其次我在windows2000 server下部署,通过浏览器可以看到提供了接口的服务,但当应用程序调用时,长时间没反应,最后没找见问题原因。这时,我不想让服务器依赖于操作系统的版本,决定放弃IIS,选择apache作为服务器;具体部署过程如下:

IIS setup

———

 Goto the IIS ControlPanel…..控制面板

  Rt.Click on My computer and select Manage

  Expand the "Servers and applications" node

  Expand the "Internet Information Server" node

  Select "Default WebSite"

  RightClick on "Default WebSite"

    Select New–> Virtual Directory

    Next

    Set Alias to  "EchoService"

    Next

    Set Directory to <DelphiPath>\Demos\WebServices\EchoService\server

    Next

    Check {Read, Run, Execute, Browse}

    Next, Finish

  From a webBrowser

   Go to http://localhost/echoservice/

   You should see the contents of the Server directory

   Click on EchoService_CGI.exe

     Expect: Default webPage

     Click on the IEchoService wsdl link

     (if in IE or NS6) you should now see the WSDL

二、第二 因为当前最新版的apache2.2.8,因此我先建立Apache2的项目

项目的目标文件可以分为两种:一种是.dll文件,另外一种是.so文件;

请在编写完项目后,千万注意,因为delphi7的版本不能支持apache2.2,所以一定要打开你的HTTPD2.pas文件,进行如下修改

MODULE_MAGIC_COOKIE =$041503232; (* "AP22" *)
MODULE_MAGIC_NUMBER_MAJOR =20051115; { Apache 2.2.x}
MODULE_MAGIC_NUMBER_MINOR =0;
LibAPR =3D ‘libapr-1.dll’; {do not localize}

第一种dll文件的项目

library ApacheTest;
 
uses
  WebBroker,
  ApacheTwoApp
  ApacheTestU in 'ApacheTestU.pas' {WebModule1: TWebModule};
 
{$R *.res}
 
exports
  apache_module name 'ApacheTest_module';
 
begin
  Application.Initialize;

  ModuleName:=’ApacheTest_module ‘;

//  Handler :=’lvyepiao2′;  //该行在我的环境下要不得

 
  Application.CreateForm(TWebModule1, WebModule1);
  Application.Run;
end.

第二种方式so文件

Note: you can also use the Application page of the project options dialog to change the extension and prefix. The other change here was to update the default exported module record name from Project1_module, resulting in:

 

library ApacheTest;

 

uses

  WebBroker,

  ApacheApp, //or ApacheTwoApp

  ApacheTestU in ‘ApacheTestU.pas’ {WebModule1: TWebModule};

 

{$R *.res}

 

{$E so}

{$LIBPREFIX ‘mod_’}

 

exports

  apache_module name ‘ApacheTest_module’;

 

begin

  Application.Initialize;

  Application.CreateForm(TWebModule1, WebModule1);

  Application.Run;

end.

 

最后就是在apache的配置了,用文本编辑器打开apache 目录下的conf目录里面的httpd.conf, 查找LoadModule最后一个的下面加入以下文本

 
LoadModule module_record_name library_name
<Location /URL>
  SetHandler content_type
</Location>

The bits you customise are:

  • module_record_name is the symbol exported by the project file and is case-sensitive. In Listing 2 you can see this is ApacheTest_module
  • library_name is taken from the ModuleName variable (from the ApacheApp unit) and defaults to the name of the shared module binary file, with any relative path needed to access it. In my example, this will be modules/mod_ApacheTest.so
  • URL is the case-sensitive URL portion that identifies what URLs should be serviced by the shared module. For the example, this will be /delphi
  • content_type is taken from the case-insensitive ContentType variable and defaults to a lowercase string that includes the module name without the extension, with -handler appended. In my example, this is mod_apachetest-handler
比如我刚才建立的项目可以在配置文件中加入:
 LoadModule ApacheTest_module modules/mod_ApacheTest.so
<Location /delphi>
  SetHandler mod_apachetest-handler
</Location>

然后http://localhost/delphi.可以访问,表明一切正常。

然而我还有一个问题没有解决:我本来想在使用系统初始化时在

后台createThread创建并启动该线程,结果线程一运行就报错。后来不得已把该线程毙了,有知道的请帮我回复下。

三、第三在apache1下就简单的多了,不存在版本问题,其它的步骤跟apache2相同,那时候apache1早就出来了,支持的挺好。我使用的apache的版本为apache1.3.22,从官网上下载就可以了。

apache1的好处就是我在apache2下不能运行的线程在这里运行跟预想的结果一致,不知道为什么?可能是2做了一些什么变动。

四、 第四就是调试方式的部署了,参考delphidemo

<DelphiPath>\Demos\WebServices\EchoService\read.txt文件中详细描述;

需要注意的是要进行调试服务器端的程序时,先设置断点后,在delphi中直接运行服务器上的程序,然后用客户端调用时就可以进行断点调试了。

WebAppDebugger Setup

——————–

  First run the Server to register it

  Goto Windows Explorer and run

    <DelphiPath>\Demos\WebServices\EchoService\server\EchoServer_WAD.exe

  Close the app

  Start the WebAppDebugger

  From the DelphiIDE: Tools| WebAppDebugger

  Press Start

  From a WebBrowser goto http://localhost:1024

  select EchoService_WAD.test_app and press go

    Expect: Default webPage

     Click on the IEchoService wsdl link

     (if in IE) you should now see the WSDL

我在实际开发和实施中不断出现问题,后面会陆续把相关的资料发布上来,以供后来参考。

分类: delphi 标签: 4,630 次阅读
原文链接:http://www.wenhq.com/article/view_202.html
欢迎转载,请注明出处:亲亲宝宝
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.