Axis开发WebService服务(DII方式)

在 Axis安装中,我们安装了Axis,现在我们开始Axis开发 。
Axis支持三种web service的部署和开发,分别为:
1.Dynamic Invocation Interface ( DII)
2.Stubs方式
3.Dynamic Proxy方式
【第一种方法】 Dynamic Invocation Interface(DII)方式
第一步:编写服务器端程序FruitQuoteService.java
[code]
import java.lang.*;
public class FruitQuoteService
{
public int getQuote(String category)
{
int quote = 0;
String apple = "apple";
String orange = "orange";
if(category.equals(apple))
{
quote = 110;
}
else if(category.equals(orange))
{
quote = 155;
}
return quote;
}
}

[/code]
第二步:将源码拷贝到AXIS_HOME下面并重命名为FruitQuoteService.jws

第三步:访问http://localhost:8080/axis/FruitQuoteService.jws?wsdl,页面显示自动生成的WSDL
接下来编写客户端代码测试
[code]
import org.apache.axis.client.*;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
public class client
{
public static void main(String[] args)
{
if(args.length <= 0)
{
System.out.println("miss fruit name!");
}
else
{
try
{
String endpoint
= "http://localhost:8080/axis/FruitQuoteService.jws";
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
call.setOperationName(new QName(endpoint, "getQuote"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));
int ret =Integer.parseInt(("" + call.invoke( new Object[]
{args[0]} )));
System.out.println("return quote is : " + ret);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
}

[/code]
编译:javac client.java
运行:java client orange
输出:return quote is :155
OK,搞定!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值