用xfire客户端调用服务端时,传递参数总是null
2012-10-12 15:30
525 查看
用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中的步骤进行服务端的配置。
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中的步骤进行服务端的配置。
相关文章推荐
- xfire客户端调用cxf服务的时候 传递过去的参数,String 类型的 老是为null
- XFire客户端调用JDK1.6的webserivce时参数为null
- 【工作记录0022】C#(.NET)调用Java开发的WebService(wsdl),客户端传递非string类型参数(int,double,bool等),而服务端无法获取到参数值的解决方案
- XFIRE 客户端 传递参数是对象 传递参数的对象所在包路径必须和服务端包路径一样。不然就出现传递过去对象值为空。
- XFire客户端调用JDK1.6+的webserivce时参数为null
- XFire客户端调用JDK1.6+的webserivce时参数为null
- 使用axis调用webservice时,服务端接收到的参数为null
- 抛弃LCDS和FMS,在tomcat下开发Red5应用(第五篇)-客户端和服务器端方法调用的参数传递
- Android 客户端调用基于XFire的webService方法传递自定义对象
- SilverLight企业应用框架设计【五】客户端调用服务端(使用JSON传递数据,自己实现RESTful Web服务)
- Xfire调用webservice无法传递参数问题解决
- xfire调用服务传入参数为null
- xfire客户端调用服务端报错 XFireRuntimeException: Could not invoke service.. Server returned error code = 4ji
- XFire实现自定义类型参数传递和调用返回自定义类型方法
- 在Android中调用KSOAP2库访问webservice服务出现的服务端传入参数为null的问题解决
- xFire两种客户端的传递参数
- XFIRE 客户端 传递参数是对象
- CXF客户端动态调用--复杂类型参数传递
- 再谈 asp.net 客户端调用服务器端事件并传递参数
- 客户端传递json格式数据,spring mvc服务端接受并进行参数校验