delphi7开发webservice部属在apache服务器中 转
delphi7开发webservice部属在apache服务器中
delphi7 webservice apache
用Delphi7开发Web Service程序,并把服务程序放在apache Web服务器上提供给各种客户程序调用。
第一步 编写服务程序
第一步:File----->New----->Other------>WebServices----->Soap Server Application
选择CGI Stand-alone executable然后确定,然后输入接口名字。
第二步:定义一个接口单元。先通过向导生成一个空的单元文件,然后在此单元中实现基本的接口(Iinvokable)和定义以后客户端程序可以调用的方法,原代码如下:
接口代码
Java代码 收藏代码
{ Invokable interface IMyWeb }
unit MyWebIntf;
interface
uses InvokeRegistry, Types, XSBuiltIns;;//基本的结构和方法的定义都在此单元中,必须引
type
{ Invokable interfaces must derive from IInvokable }
IMyWeb = interface(IInvokable) //自定义的一个结构,继承自Iinvokable
['{E3070F4D-AEBF-47D6-963B-ADFFC4E7C7A1}'] //通过Ctrl+Shift+G生成的一个GUID
{ 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(IMyWeb));//通过此方法来注册接
end.
第三步:实现第二步中所定义的接口和方法。先通过向导生成一个空的单元文件,然后定义自定义接口(IWebtest)的实现类。原代码如下:
实现接口代码
Java代码 收藏代码
{ Invokable implementation File for TMyWeb which implements IMyWeb }
unit MyWebImpl;
interface
uses InvokeRegistry, Types, XSBuiltIns, MyWebIntf,Unit1;//引用自定义的接口单元
type
{ TMyWeb }
TMyWeb = class(TInvokableClass, IMyWeb)//定义实现类,此类必须继承自TInvokableClass,并实现自定义接
public
function gettext():widestring;stdcall;//申明在自定义接口中所定义的方法
end;
implementation
function TMyWeb.gettext: widestring;//实现自定义方法
begin
Result:='Success';
end;
initialization
{ Invokable classes must be registered }
InvRegistry.RegisterInvokableClass(TMyWeb);
end.
第四步:编译整个应用程序,即产生一个*.exe的程序,把此程序拷贝到apache的Cgi-bin目录下,然后即可通过以下方式的链接访问到Wsdl:http://127.0.0.1/cgi-bin/*.exe访问到以XML方式编码的Wsdl文件了,这就是客户端程序调用需要的文件。其中*.exe为你自己的应用程序的名字。127.0.0.1为你的Web服务器地址。Cgi-bin为你的Web服务器的可以执行Cgi程序的目录名称 或 虚拟目录名称。
第二步 编写客户程序:
第一步:新建一个Application。
第二步:File----->New----->Other------>WebServices----->Soap Services Importer
然后在Wsdl or Xml Schema Location中填入:.exe/wsdl/IMyWeb,然后确定即生成了一个新的接口定义单元。
生成的代码
Java代码 收藏代码
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://127.0.0.1:8090/cgi-bin/Project2.exe/wsdl/IMyWeb
// Encoding : utf-8
// Version : 1.0
// (2011-7-22 16:14:10 - 1.33.2.5)
// ************************************************************************ //
unit IMyWeb1;
interface
uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;
type
// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema"
// ************************************************************************ //
// Namespace : urn:MyWebIntf-IMyWeb
// soapAction: urn:MyWebIntf-IMyWeb#gettext
// transport : http://schemas.xmlsoap.org/soap/http
// style : rpc
// binding : IMyWebbinding
// service : IMyWebservice
// port : IMyWebPort
// URL : http://127.0.0.1:8090/cgi-bin/Project2.exe/soap/IMyWeb
// ************************************************************************ //
IMyWeb = interface(IInvokable)
['{85474E46-8BF2-FC4E-8A91-6FC82BB6EBF1}']
function gettext: WideString; stdcall;
end;
function GetIMyWeb(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): IMyWeb;
implementation
function GetIMyWeb(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IMyWeb;
const
defWSDL = 'http://127.0.0.1:8090/cgi-bin/Project2.exe/wsdl/IMyWeb';
defURL = 'http://127.0.0.1:8090/cgi-bin/Project2.exe/soap/IMyWeb';
defSvc = 'IMyWebservice';
defPrt = 'IMyWebPort';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as IMyWeb);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(IMyWeb), 'urn:MyWebIntf-IMyWeb', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(IMyWeb), 'urn:MyWebIntf-IMyWeb#gettext');
end.
第二步:在主form上放上一个按钮, 并引用第二个单元(即通过Soap Services Importer自动生成的单元)
第三步:编写客户调用程序,原代码如下:
Java代码 收藏代码
unit MyWebImpl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IMyWeb1, StdCtrls;
//IMyWeb1 为引入自动生成的webservice服务器接口
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
testobj:IMyWeb;//定义对象
begin
testobj:=GetIMyWeb;//创建对象
showmessage(testobj.gettext);//调用方法
end;
end.
最后运行程序,点击Button,会弹出success的对话框,证明测试成功。
本人是初学delphi,很多方面不是很懂,通过浏览和总结网络中的例子,自己测试通过。因为网上好多例子不能运行,(可能是自己有些地方不懂吧)所以自己把测试通过的项目发布到博客中。
源码下载地址: http://yunpan.cn/Q9mrPhqBB8Dhj
delphi7开发webservice部属在apache服务器中 转的更多相关文章
- django项目部署在Apache服务器中,静态文件路径的注意点
django Apache部署静态文件的路径注意点 静态文件放在对应的 app 下的 static 文件夹中 或者 STATICFILES_DIRS 中的文件夹中. 当 DEBUG = True 时, ...
- Windows下Apache服务器中自动配置二级子域名
今天我们介绍的这个办法,只需要简单修改 httpd-vhosts.conf 文件,配合 .htaccess 文件即可实现自动配置二级域名. 我们这里以 wpchina.com 为例,以下代码中的 wp ...
- Apache服务器中运行CGI程序的方法,文中以Perl脚本作为示例
关于apache与CGI在这里就不解释了. 1.apache下面以2.0.63为例介绍运行CGI程序的配置.(http://www.nklsyy.com) 2.下载Windows下的Perl解释器Ac ...
- Apache服务器中配置虚拟机的方法
新浪微博虚拟机开发配置步骤及介绍.1.由于后面虚拟机中需要用到Rewrite所以先编辑Apache的conf目录下的httpd.conf文件.(可根据实际需要操作)添加mod_rewrite.so模块 ...
- apache服务器中设置目录不可访问
<Directory "d:/amp/apache/htdocs/images"> Allow from all Options None</Dire ...
- thinkphp项目在apache服务器中“去掉”index.php后出现找不到url的问题
今天将MAC中apache环境下的thinkphp项目移植到windows中得apache环境下.原本都是apache环境,而且配置都一样,死活给我这样的提示: Not Found The reque ...
- Apache服务器中设置端口映射和反向代理的方法
在/etc/httpd/conf路径下的httpd.conf文件###new add for webui.cong###Include "E:/local/Wamp/bin/apache/A ...
- Nginx和apache服务器中php运行方式
PHP5的CGI方式的一大优势是内置了FastCGI的支持,只需指明绑定的地址和端口参数便可以以FastCGI的方式运行,如下: php-cgi -b 127.0.0.1:9000 配置Nginx的P ...
- 在Apache服务器中禁用option
在apache禁止 http OPTIONS方法. apache disable http OPTIONS method 2013-04-17 09:27 4050人阅读 评论(1) 收藏 举报 分 ...
随机推荐
- RMAN-00554: initialization of internal recovery manager package failed RMAN-04005
[oracle@rac11g1 ~]$ rman target haha/haha@rac11g Recovery Manager: Release 11.2.0.3.0 - Production o ...
- HDU 3791 二叉搜索树 题解
Problem Description 推断两序列是否为同一二叉搜索树序列 Input 開始一个数n,(1<=n<=20) 表示有n个须要推断,n= 0 的时候输入结束. 接下去一行是 ...
- Android 自定义View (四) 视频音量调控
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24529807 今天没事逛eoe,看见有人求助要做一个下面的效果,我看下面一哥们说 ...
- 在公网上布署Web Api的时候,不能调用,返回404
在internet上布署web API做的站点时,发现不能调用web api的任何action, 返回404. 经过很多的努力,也找不到原因,环境是win server 2008, IIS 75. n ...
- JavaScript中几个可以转化为false的值
1.[0,NaN,“”,null,undefined]都可以直接转化为false,但这几个值不是完全相等的 var arr = [0,"",false,null,undefined ...
- Hibernate 关联查询 相关错误
错误提示: could not resolve property: 确定有相关属性时,记得使用 criteria.createAlias @ManyToOne 若可能为null 要加上 @NotFou ...
- 数据库连接超时和go away、如何检测数据库的最大连接数
搜索连接bi库超时 数据库连接超时 go away go away和连接超时之间的关系是什么? 写一个例子测试一下. 如何检测数据库的最大连接数
- Eclipse自动提示功能
一般默认情况下,Eclipse的代码提示功能是比MicrosoftVisualStudio的差很多的,主要是Eclipse本身有很多选项是默认关闭的,要开发者自己去手动配置.如果开发者不清楚的话,就不 ...
- 电厂MIS,SIS简介
MIS(Management Information System)管理信息系统,主要指的是进行日常事务操作的系统,它使管理人员及时了解公司现状和各种消息,它是电力企业管理现代化的重要标志. 一个典型 ...
- iOS 网络与多线程--1.检测网络链接状态
通过Reachability库,检测设备的网络连接状况. 使用到的类库:Reachability Reachability库,是一个iOS环境下,检测设备网络状态的库,可以在网络上搜索下载. 使用之前 ...