用xfire客户端调用服务端时,传递参数总是null

用xfire客户端调用服务端时,传递参数总是null的问题:
1、接口方法返回的复杂类型(如对象类型、数组类型等基本类型之外的类型),特别是对象类型,对象类所在的包结构与客户端该对象所在的包结构一致;
2、服务端的接口类上面加了@WebService,具体方法上加了@WebResult、@WebParam(name="userid",targetNamespace="http://webService/"),接口实现类上也加了@WebService(endpointInterface="webService.CardWebService",portName="CardWebServicePort",serviceName="CardWebService");
3、用xfire编写的客户端如下:
  Service service = new ObjectServiceFactory()
                 .create(CardWebService.class,null,"http://webService/",null);//CardWebService为webservice接口类
   XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
                 .newInstance().getXFire());
   //XFireProxyFactory factory = new XFireProxyFactory();
   String url = "...WebService?wsdl";//wsdl地址
   try {
        CardWebService cws = (CardWebService) factory.create(service, url);
         Test result = cws.queryPersonInfo("", "", "", "", "123456789");//服务端queryPersonInfo方法的返回类型为Test
         //...
  } catch (MalformedURLException e) {
         e.printStackTrace();
   }
4、上述代码执行后,服务端接受的参数总是null,这说明客户端将方法的参数传递到服务端时,服务端没办法接受到传递过来的参数。出现此类问题的原因,暂时不清楚(望高手能留言帮我解决,谢谢!)。但是找到了如下的处理办法:
  用xfire编写的客户端如下:
  public static void main(String[] args) throws Exception {     
  String url = "...WebService?wsdl";//wsdl地址  
  Client client = new Client(new URL(url));        
  Object[] names = client.invoke("queryPersonInfo", new Object[] {"", "", "", "", "123456789"});   
  System.out.println("names[0]=" + names[0]);// 输出结果:names[0]=[#document: null],但是服务端能接受到客户端传递来的参数 
  Document xmlTree = (Document) names[0];     
  anylizeElement(xmlTree);  
 }  
 private static void anylizeElement(Document xmlTree) {      
  Element element = xmlTree.getDocumentElement();    
  System.out.println(element.getFirstChild().getFirstChild().getNodeName());   
  System.out.println(element.getFirstChild().getFirstChild().getNodeValue());    
  NodeList children = element.getChildNodes();     
  for (int i = 0; i < children.getLength(); i++) {    
   Node node = children.item(i);      
   stepThrough(node);      
  } 
 } 

 private static void stepThrough(Node start) {   
  for (Node child = start.getFirstChild(); child != null; child = child.getNextSibling()) {    
   if (child instanceof Node)// 去除多余的空白       
   {            
    System.out.print("节点名:" + child.getNodeName());   
    System.out.println("\t节点值:" + child.getNodeValue());    
   }      
   if (child != null){    
    stepThrough(child);    
   }   
  }
 }
5、执行上述代码后,服务端能接受到客户端传递来的参数,并且客户端也能接受到服务端返回的数据,只不过客户端要将document进行解析。并且编写上述代码后,3中Test类所在的包结构不再要求服务端和客户端保持一致。
6、如果先根据wsdl生成本地客户端,再编写类调用生成的本地客户端的方式来访问服务端,以此种方式访问服务端出现服务端接受参数为null的情况的话,那可以按照2中的步骤进行服务端的配置。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值