日期:2008-10-30 浏览次数:20437 次
作者:wjhdtx
摘自csdn
简单的webservice开发例子
Axis支持三种web service的部署和开发,分别为:
1、Dynamic Invocation Interface ( DII)
2、Stubs方式
3、Dynamic Proxy方式
二、编写DII(Dynamic Invocation Interface )方式web服务
1.编写服务端程序HelloClient
public class HelloClient
{
public String getName(String name)
{
return "hello "+name;
}
}
2、将源码拷贝到Axis_HOME下,重命名为 HelloClient.jws
3、访问连接http://localhost:8080/Axis/HelloClient.jws?wsdl,页面显示Axis自动生成的wsdl
4、编写访问服务的客户端 TestHelloClient.java
import org.apache.Axis.client.Call;
import org.apache.Axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
public class SayHelloClient2
{
public static void main(String[] args)
{
try
{
String endpoint =
"http://localhost:8080/Axis/HelloClient.jws";
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
call.setOperationName(new QName(
"http://localhost:8080/Axis/HelloClient.jws",
"getName"));
call.setTargetEndpointAddress
(new java.net.URL(endpoint));
String ret = (String) call.invoke(new Object[]
{"zhangsan"});
System.out.println("return value is " + ret);
}
catch (Exception ex)