dotnet调用delphi写的cgi

作  者: ilovedotnetthandelph ()
等  级: 
信 誉 值: 100
所属社区: Delphi 网络通信/分布式开发
问题点数: 0
回复次数: 1
发表时间: 2006-5-11 12:31:14

最近写了一个关于dotnet调用delphi写的cgi的程序,参考了网上很多网友发的帖子,这里我将大家的内容加上我自己的心得写一篇,让后来像我这样的小虾少走点弯路。

一、用Delphi开发Web Service程序
打开Delphi7.0的开发环境,依次选择New | Other | WebServices | SOAP Server Application,然后选择CGI Stand-alone executable,系统将自动包含进开发Web Service所需要的类。在弹出的confirm窗口中点击确定,并在Add new services窗口中输入services name:test,系统自动生成工程,将新建工程保存为testservices。
编辑文件testImpl、testIntf生成调用接口,编辑后的文件如下,其中红色字体为自己添加的代码,蓝色字体是申明的接口。
testIntf:
{ Invokable interface Itest }

unit testIntf;

interface

uses InvokeRegistry, Types, XSBuiltIns;

type

  { Invokable interfaces must derive from IInvokable }
  Itest = interface(IInvokable)
  ['{FE47D43F-59DF-4AF9-ACD4-BA3882C01B31}']

    { Methods of Invokable interface must not use the default }
    { calling convention; stdcall is recommended }
    function gettext():widestring;stdcall;//申明在自定义接口中所定义的方法
  end;

implementation


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

end.

testImpl:
{ Invokable implementation File for Ttest which implements Itest }

unit testImpl;

interface

uses InvokeRegistry, Types, XSBuiltIns, testIntf;

type

  { Ttest }
  Ttest = class(TInvokableClass, Itest)
  public
   function gettext():widestring;stdcall;//申明在自定义接口中所定义的方法
  end;

implementation
function Ttest.gettext: widestring; stdcall;//实现自定义方法
begin
Result:='Success';
end;

initialization
  { Invokable classes must be registered }
  InvRegistry.RegisterInvokableClass(Ttest);

end.

这样就生成一个返回字符串类型的接口方法。
二、把服务程序放在IIS Web服务器上提供给各种客户程序调用。
在IIS的默认站点里面新建一个虚拟目录delphi-cgi,并将该虚拟目录的执行权限设置为“脚本和可执行文件”以使该目录具有执行ISAPI扩展的权限,将虚拟目录指向该工程的文件夹。
三、在dotnet中调用该webservies。
在dotnet中添加web引用,在添加web引用窗口的URL栏中填入delphi的webservies的URL地址:http://localhost/delphi-cgi/testservices.exe/wsdl/Itest(如图1),点击转到,系统会自动发现接口(如图2),在web引用名栏中输入testservices,点击添加引用,系统将添加该引用(如图3)。
在WebForm1.aspx上添加button、textbox,在WebForm1.aspx.cs中添加代码:
using WebService1. testservices;
在事件Button1_Click中添加代码:
WebService1.testservices.Itestservice tt=new WebService1.testservices.Itestservice();
TextBox1.Text=tt.gettext();
运行程序在文本框中会显示字符“success”。

图看不到。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值