今天开始从头学习java web服务开发的学习,主要是axis的学习,在这里做个笔记,以后再看可也记得住

 在布置axis环境是,在classpath中有toors.jar,在tomcat中也有toors.jar,当然在axi中也有的了,但是浏览器浏览jws文件时,报错,说是让我添加toors,jar文件,不知道为什么了,想到难道是jdk版本和axis不兼容,就把tomcat的jdk换成1.6了,果然可以了,但是具体内部是不是这个问题,还是不很清楚。。。

下面是第一种发布方式:即时发布(Instant Deloyment)

  1. public class HelloWorldJWS {  
  2.       
  3.     public String test(String a,String b){  
  4.         String result =  "a="+a+" ,b="+b;  
  5.         System.out.println("Received is"+result);  
  6.         return "Server Response OK,you send: "+result;  
  7.     }  

然后是客户端

 

  1. import java.rmi.RemoteException;  
  2.  
  3. import javax.xml.namespace.QName;  
  4. import javax.xml.rpc.ServiceException;  
  5.  
  6. import org.apache.axis.client.Call;  
  7. import org.apache.axis.client.Service;  
  8.  
  9.  
  10. public class ClientJWS {  
  11.  
  12.     /**  
  13.      * @param args  
  14.      * @throws ServiceException   
  15.      * @throws RemoteException   
  16.      */ 
  17.     public static void main(String[] args) throws ServiceException, RemoteException {  
  18.         // TODO Auto-generated method stub  
  19.           
  20.         String url = "http://localhost:8000/axis/HelloWorldJWS.jws";  
  21.         Service service = new Service();  
  22.         Call call = (Call)service.createCall();  
  23.         call.setTargetEndpointAddress(url);  
  24.           
  25.         call.setOperationName(new QName(url,"test"));  
  26.         String result = (String)call.invoke(new Object[]{"diandian","100"});  
  27.         System.out.println("result="+result);  
  28.           
  29.     }  
  30.  

在运行客户端时还需要在工程类库中添加commons-logging-1.0.4.jar ,commons-discovery.jar,即时发布不支持带包的类。

第一次作业笔记