webservice现在已经不是什么新
技术了,用
java建立webservice是快捷的,但是用
java在制作客户端的感觉上总是不如
delphi的(个人感觉,
java高手们不要
笑话我),那我们就用
java实现webservice的服务端程序,
delphi制作客户端。
一.环境搭建
jdk和tomcat的安装和配置我在这里不进行行介绍了。说明一点我的tomcat是安装在D:tomcat,设定端口是8099。
安装Axis
1.可以从
http://ws.apache.org/axis/下载axis的最新版本,我使用的是axis1.2。
2.解压缩axis-bin-1_2beta.zip,将axis-1_2beta目录中webapps下的axis目录全部拷贝到tomcat的安装目录中webapps下。
3.将axislib中的所有jar文件都添加到classpath系统变量中。
注(用户需根据自己的安装路径进行更改):
.;
d:tomcatwebappsaxisWEBINFlibaxis.jar;
d:tomcatwebappsaxisWEB-INFlibsaaj.jar;
d:tomcatwebappsaxisWEB-INFlibcommons-logging.jar;
d:tomcatwebappsaxisWEB-INFlibcommons-discovery.jar;
d:tomcatwebappsaxisWEB-INFlibwsdl4j.jar;
d:tomcatwebappsaxisWEBINFlibjaxrpc.jar;
4.启动tomcat访问
http://cbf107:8099/axis/index.html(这里使用的主机名和端口号和使用的tomcat所配置一致)。
二.Web Service服务端开发
写一个
java小程序:
public class Test{
public int add(int p1, int p2) {
return p1 + p2;
}
public int subtract(int p1, int p2) {
return p1 - p2;
}
}
在D:Tomcatwebappsaxis 目录下新建一个test文件夹,将它保存在里面,注意:后缀名改为jws,也就是Test.jws 。
在浏览器里访问:
http://cbf107:8099/axis/test/Test.jws 点击“Click to see the WSDL”出现
将这页另存为xml文档(我们在使用
delphi制作客户端的时候会使用)
三.
delphi实现Web Service客户端开发
打开
delphi新建工程,在form上放置两个edit和两个button,button的name命名为
btnadd和btnsubtract,caption命名为add和subtract。
再file->new->other,选择webservice里的WSDL importer
在search UDDI..里选择前面我们保存的那个xml文件,点击next最后finish
全部保存,我们发现
delphi的工程中多了test1.pas
打开发现有这样一段接口申明:
Test =
interface(IInvokable)
['{52882FF0-46E2-6644-A77B-CE714D4CBFD5}']
function add(const p1: Integer; const p2: Integer): Integer; stdcall;
function subtract(const p1: Integer; const p2: Integer): Integer; stdcall;
end;
那我们可以直接调用这个接口了,这时候我们回到界面,从
delphi的webservices面版中托放一个soap到form上