posts - 32,comments - 8,trackbacks - 0
reference:
 part1


1. in package explorer, change myService.java:
package com.service;
public class myService {
public String getusername(String name){
        
return "Hello "+name+",this is an Axis Web Service";
    }
}
and ctrl+1 to solve the package problem( or you can create dir and move file yourself)

2.in WebContent/WEB-INF/, create server-config.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>    
   
<service name="myService" provider="java:RPC">
        
<parameter name="className" value="com.service.myService"/>
        
<parameter name="allowedMethods" value="getusername"/>
    
</service> 
<transport name="http">
 
<requestFlow>
    
<handler type="URLMapper"/>
 
</requestFlow>
</transport>
</deployment>

3. in src/, create myServiceTestorByWSDD.java
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class myServiceTestorByWSDD {
public tatic void main(String[] args) throws ServiceException,MalformedURLException, RemoteException {
        String endpoint 
= http://localhost:8080/oopsaxis1/services/myService;
        Service service 
= new Service();                // 创建一个Service实例,注意是必须的!
        Call call = (Call) service.createCall();   // 创建Call实例,也是必须的!
        call.setTargetEndpointAddress(new java.net.URL(endpoint));// 为Call设置服务的位置
        call.setOperationName("getusername");              // 注意方法名与JavaBeanWS.java中一样!!
        String res = (String) call.invoke(new Object[] { "pixysoft" });       // 返回String,传入参数
        System.out.println(res);
}
}

4. open tomcat, and :http://localhost:8080/oopsaxis1/servlet/AxisServlet,you can see:
And now Some Services
myService (wsdl) 
getusername 

5. right click myServiceTestorByWSDD.java, run as java application.


done!

posted on 2008-12-17 13:51 张辰 阅读(252) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: