一步一步用Delphi6实现Web Service

      本文介绍的是如何用Delphi6开发Web Service程序,并把服务程序放在IIS Web服务器上提供给各种客户程序调用。

一编写服务程序

第一步:File----->New----->Other------>WebServices----->Soap Server Application

选择ISAPI/NSAPI Dynamic Link Library然后确定。生成一个框架。后面的大部分原代码都需要自己手工添加

第二步:定义一个接口单元。先通过向导生成一个空的单元文件,然后在此单元中实现基本的接口(Iinvokable)和定义以后客户端程序可以调用的方法,原代码如下:

unit unit1;
interface
uses  InvokeRegistry;//基本的结构和方法的定义都在此单元中,必须引用
type
IWebTest=interface(Iinvokable)//自定义的一个结构,继承自Iinvokable
['{A436B0D2-D490-4C80-820A-355D979E8704}']//通过Ctrl+Shift+G生成的一个GUID
function gettext():widestring;stdcall;//自定义的一个方法,也是以后客户可以调用的方法
end;
implementation

initialization//初始化
InvRegistry.RegisterInterface(Typeinfo(IWebTest));//通过此方法来注册接口
end.

第三步:实现第二步中所定义的接口和方法。先通过向导生成一个空的单元文件,然后定义自定义接口(IWebtest)的实现类。原代码如下:

unit Unit2;

interface
uses  InvokeRegistry,Unit1;//引用自定义的接口单元
type
TWebTest=class(TInvokableClass,IWebTest)//定义实现类,此类必须继承自TInvokableClass,并实现自定义接口
protected
function gettext():widestring;stdcall;//申明在自定义接口中所定义的方法
end;
implementation

{ Test }
procedure createwebtest(out obj:tobject);//此过程为创建类实例,必须手工添加
begin
obj:=TWebTest.Create;//创建类实例
end;
function TWebTest.gettext: widestring;//实现自定义方法
begin
Result:='Success';
end;
initialization//初始化
InvRegistry.RegisterInvokableClass(TWebTest,createwebtest);//注册自定义类
end.

第四步:编译整个应用程序,即产生一个*.dll的程序,把此程序拷贝到IIS的Cgi-bin目录下(或者其他可执行的目录,要根据自己的目录来选择),然后即可通过以下方式的链接访问到Wsdl:http://192.168.1.222/cgi-bin/*.dll/wsdl访问到以XML方式编码的Wsdl文件了,这就是客户端程序调用需要的文件。其中*.dll为你自己的应用程序的名字。192.168.1.222为你的Web服务器地址。Cgi-bin为你的Web服务器的可以执行Cgi程序的目录名称。

 

二编写客户程序:

第一步:新建一个Application。

第二步:File----->New----->Other------>WebServices----->Soap Services Importer

然后在Wsdl or Xml Schema Location中填入:http://192.168.1.222/cgi-bin/*.dll/wsdl/IWebTest,然后确定即生成了一个新的接口定义单元。

第二步:在主form上放上一个按钮和一个Httprio组件(在WebServices页上),并引用第二个单元(即通过Soap Services Importer自动生成的单元)

在Httprio的属性页上的WsdlLocation里面填上http://192.168.1.222/cgi-bin/*.dll/wsdl/IWebTest;然后在Httprio属性页上的Port和Service上选择上相应的数据即可。

第三步:书写客户调用程序,原代码如下:

procedure TForm1.Button1Click(Sender: TObject);
var
testobj:IWebTest;//定义对象
begin
testobj:=Httprio1 as IWebTest;//创建对象
showmessage(testobj.gettext);//调用方法
end;

以上是一个简单的例子,有兴趣的可以和我讨论。以上的例子还用java客户调用通过。我的邮箱是coala@21cn.com

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Delphi中,可以使用TColorDialog组件实现颜色选择对话框。如果想要自定义颜色选择对话框,可以继承TColorDialog并重写其中的一些方法。 下面是一个简单的示例代码,演示如何实现自定义颜色选择对话框: ```delphi unit CustomColorDialog; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type TCustomColorDialog = class(TColorDialog) private FCustomColors: array[0..15] of TColor; protected procedure DoShow; override; procedure PaintRect(Canvas: TCanvas; Rect: TRect; Color: TColor); virtual; public constructor Create(AOwner: TComponent); override; published property CustomColors: array[0..15] of TColor read FCustomColors write FCustomColors; end; procedure Register; implementation {$R *.dfm} constructor TCustomColorDialog.Create(AOwner: TComponent); begin inherited; FCustomColors[0] := clBlack; FCustomColors[1] := clMaroon; FCustomColors[2] := clGreen; FCustomColors[3] := clOlive; FCustomColors[4] := clNavy; FCustomColors[5] := clPurple; FCustomColors[6] := clTeal; FCustomColors[7] := clGray; FCustomColors[8] := clSilver; FCustomColors[9] := clRed; FCustomColors[10] := clLime; FCustomColors[11] := clYellow; FCustomColors[12] := clBlue; FCustomColors[13] := clFuchsia; FCustomColors[14] := clAqua; FCustomColors[15] := clWhite; end; procedure TCustomColorDialog.DoShow; var I: Integer; BtnRect, ColorRect: TRect; BtnWidth, BtnHeight, ColorWidth, ColorHeight: Integer; BtnTop, ColorTop, ColorLeft: Integer; BtnCaption: string; BtnFont: TFont; BtnColor: TColor; Canvas: TCanvas; begin inherited; Canvas := TCanvas.Create; try Canvas.Handle := GetDC(Handle); BtnWidth := 50; BtnHeight := 20; ColorWidth := 15; ColorHeight := 15; BtnTop := ClientHeight - BtnHeight - 10; ColorTop := 10; ColorLeft := ClientWidth - 20 - (4 * ColorWidth); BtnFont := TFont.Create; try BtnFont.Assign(Font); BtnFont.Style := [fsBold]; for I := 0 to 3 do begin BtnRect := Rect(20 + (I * BtnWidth), BtnTop, 20 + ((I + 1) * BtnWidth), BtnTop + BtnHeight); BtnColor := CustomColors[I]; PaintRect(Canvas, BtnRect, BtnColor); BtnCaption := 'Color ' + IntToStr(I + 1); Canvas.Font := BtnFont; Canvas.Brush.Style := bsClear; DrawText(Canvas.Handle, PChar(BtnCaption), -1, BtnRect, DT_SINGLELINE or DT_CENTER or DT_VCENTER); for J := 0 to 3 do begin ColorRect := Rect(ColorLeft + (J * ColorWidth), ColorTop + (I * ColorHeight), ColorLeft + ((J + 1) * ColorWidth), ColorTop + ((I + 1) * ColorHeight)); PaintRect(Canvas, ColorRect, CustomColors[(I * 4) + J]); end; end; finally BtnFont.Free; end; finally ReleaseDC(Handle, Canvas.Handle); Canvas.Free; end; end; procedure TCustomColorDialog.PaintRect(Canvas: TCanvas; Rect: TRect; Color: TColor); begin Canvas.Brush.Color := Color; Canvas.Pen.Color := Color; Canvas.Rectangle(Rect); end; procedure Register; begin RegisterComponents('Samples', [TCustomColorDialog]); end; end. ``` 以上代码中,我们创建了一个名为TCustomColorDialog的自定义颜色选择对话框。在DoShow方法中,我们使用TCanvas绘制了自定义颜色区域和按钮区域。在PaintRect方法中,我们绘制了矩形,并填充了指定的颜色。 要使用自定义颜色选择对话框,只需将TCustomColorDialog组件放置在窗体中,并将其Execute方法调用即可:CustomColorDialog1.Execute。 希望这个示例对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

coala

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值