dotnet调用delphi写的cgi

ilovedotnetthandelph 2006-05-11 12:28:38
最近写了一个关于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”。
图1

图2

图3

...全文
153 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cangwu_lee 2007-02-20
  • 打赏
  • 举报
回复
delphi .net 可以和 c# 一样的生成了
pilicat 2007-02-16
  • 打赏
  • 举报
回复
喔,还没有用Delphi做过Web Service 呢。
whereto 2006-05-26
  • 打赏
  • 举报
回复
Delphi开发Web Service程序时如何返回数据集呢?如果返回了,其他系统怎么调用?

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧