在 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,搞定!
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,搞定!