Web Services学习之单独exe服务器

最近开始接触web services,在网上找了些例子做了下,主要是实现单个exe的web services服务的实现:

我总结有一下几点要注意:

1:新建一个SOAP Server Application工程,方式选择debuger,向导自动生成的代码中:
initialization
TWebAppSockObjectFactory.Create('Han');
是为了debuger服务器而生成的,这里我不需要所以删除.并去掉相关引用

2:Indy Http Server来发布你的Soap,你需要引用一个Unit,这个文件就是 \Borland\Delphi7\Source\Indy\IdHTTPWebBrokerBridge.pas uses IdHTTPWebBrokerBridge 后还要在工程的搜索路径中添加这个该pas所在的路径

3:如何知道默认debugger的http地址?既然要用单独exe来做了这个并不重要,但作为知识点我还是记录下.在Tools->web app debugger 中可以看到.

以下是我主窗体的代码:

unit Unit1;

interface

uses
SysUtils, Classes, Forms, IdHTTPWebBrokerBridge;

type
TForm1 
= class(TForm)
    
procedure FormCreate(Sender: TObject);
private
    ser: TIdHTTPWebBrokerBridge;
    
{ Private declarations }
public
    
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;


{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ser :
= TIdHTTPWebBrokerBridge.Create(self);
ser.DefaultPort :
= 5678;
ser.Active :
= true;
ser.RegisterWebModuleClass(TWebModule2);
end;

initialization
//TWebAppSockObjectFactory.Create('Han')

end.

 

接口地址是:http://localhost:5678/

以下是我在网上搜集的文章:

早段时间看了一篇好文章,对其整理成以下几步

1新建一个SOAP Server Application,在提示输入接口时输入MyHello,把所有文件
保存在一个叫Ser的目录下,其中一个包含TWebModule1的文件保存为main.pas.
在MyHelloIntf.pas的IMyHello接口中加入
function Welcome(name:string):string;stdcall;  

在MyHelloImpl.pas中的TMyHello实现此方法

function TMyHello.Welcome(name:string):string;
begin
  result:
='Welcome '+name;
end;



2新建一个标准Application,把所有文件保存在刚才哪个Ser目录下(同一目录).
文件名默认,在Unit1.pas中Uese IdHTTPWebBrokerBridge,可能还要在工程
的Search path加入<Delphi7>\Source\Indy <Delphi7>是Delphi的安装目录
3在form1上放一个lable,写上"Stand Alone Web Service"
4在TForm1的private中加入一个变量ser:TIdHTTPWebBrokerBridge;
5Uses第一步中的main.pas MyHelloIntf.pas MyHelloImpl.pas
7在OnFormCreate事件上写

ser:=TIdHTTPWebBrokerBridge.Create(self);
ser.DefaultPort:
=5678;
ser.Active:
=true;
ser.RegisterWebModuleClass(TWebModule1);


8运行程序,打开IE,输入http://localhost:5678/.结果大家都想到了

写Client
1关闭所有文件.
2新建一个标准Application
3运行刚才写的服务器Application
4运行wsdl import wizard,在URL中输入http://localhost:5678/wsdl/IMyHello
按Next几次
5保存所有文件到一个新目录,用Wizard产生的文件保存为IMyHello1.pas,其余默认,在Unit1.pas中uses

IMyHello1.pas,放一个TButton,写上下面的代码,运行.

procedure TForm1.Button1Click(Sender: TObject);
var
I:IMyHello;
begin
I:
=GetIMyHello;
ShowMessage(I.Welcome(
'black man'));
I:
=nil;
end;


posted @ 2009-07-27 12:57  Handll  阅读(480)  评论(0编辑  收藏  举报