WebService做媒,Delphi与Java牵手

环境:Win7、Delphi7、JDK6、Tomcat6、XFire1.2

 

Web服务端:

Iweather.java

package net.ly.webservice.biz;

public interface Iweather {
 String weather(String s);
 String weather2();
}

 

WeatherImpl.java

package net.ly.webservice.impl;

import net.ly.webservice.biz.Iweather;

public class WeatherImpl implements Iweather {

 public String weather(String s) {  
  return "Hello " + s ;
 }
 

 public String weather2() {  
  return "abcde2";
 }

}

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>XFireServlet</servlet-name>
    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>XFireServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
</web-app>

 

services.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
 <service>
  <name>Weather</name>
  <namespace>www.weather.com/Weather</namespace>
  <serviceClass>net.ly.webservice.biz.Iweather</serviceClass>
  <implementationClass>net.ly.webservice.impl.WeatherImpl</implementationClass>
 </service>

</beans>

 

Web服务目录结构如图:

 

图片

 部署,启动Tomcat。

 

 

Delphi代码部分:

cmd打开DOS窗口,cd进入 D:\Program Files\Borland\Delphi7\Bin

WSDLImp http://localhost:8686/myWebService/services/Weather?wsdl

 

在当前目录生成Weather.pas

 

新建Delphi项目,保存项目到文件夹javawebservice,把Weather.pas再拷贝到这个文件夹,然后加入到项目中。

 

在Unit1文件引用Weather,

 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses  Weather;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   s,s2:string;
begin
      s:=GetWeatherPortType().weather('dai');
      showmessage(s);
      s2:=GetWeatherPortType().weather2;
      showmessage(s2);
end;

end.

 

 Delphi程序运行界面:

 

图片

 

Web应用和Delphi桌面应用结合,对现实项目开发,解决方案更加灵活,能够打出一套漂亮的组合拳。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值