liuhuan1534 发表于 2013-1-15 02:00:50

WebService-xfire客户端调用示例

import java.net.URL;
import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
 
 
     Object[] params = { compCde, userId, taskNum, taskTotalNum };
     String ws_url = ConfigUtils.getActionAttribute("WS_GPSTASKCOUNT_URL");
     String ws_method = ConfigUtils.getActionAttribute("WS_GPSTASKCOUNT_METHOD"); // 调用方法\
     Client client = new Client(new URL(ws_url));
     XFire xfire = XFireFactory.newInstance().getXFire();         
     client.setXFire(xfire);
     Object[] os = client.invoke(ws_method, paramsObject);
     if(os!=null&&os.length>0){
        result = os;
     }
 
 
-------------------------------------------------------------------------------------------------------------------------
 

import java.net.MalformedURLException;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import com.***.edp.webservice.vo.ReturnMsg;
import com.***.edp.webservice.vo.TaskBaseInfo;
public class TaskServiceTest {
 
 /**
  * 客户端调用测试-参数中含有自定义类型
  * @param args
  * @throws Exception
  */
 public static void main(String[] args) throws Exception{ 
  try{
   //组装调用参数......
   TaskBaseInfo taskBaseInfo = new TaskBaseInfo();
   
   String ws_url = "http://localhost:8888/claim/services/TaskService";//注意与参数只有简单类型的有区别
   Service model = new ObjectServiceFactory().create(TaskService.class);
   XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
   TaskService service = (TaskService) factory.create(model, ws_url);
   ReturnMsg returnMsg = service.saveTask(taskBaseInfo);
   //0表示该用户名不存在;1表示登录成功;2表示该用户已禁用;3表示密码不对!;
   if (returnMsg.getCode() == 1)
    System.out.println("任务保存成功!");
   else
    System.out.println("任务保存失败:" + returnMsg.getMessage());
  } catch (MalformedURLException e) {            
   e.printStackTrace();
   throw new Exception("远程服务访问出错!");
  } catch (Exception e){
   e.printStackTrace();
   throw new Exception("远程服务访问出错!");
  }
 }
}
 
页: [1]
查看完整版本: WebService-xfire客户端调用示例