webservice 接口用java中的axis调用,java编程传递一个参数String[]给网络接口为啥报错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webservice 接口用java中的axis调用,java编程传递一个参数String[]给网络接口为啥报错相关的知识,希望对你有一定的参考价值。
要传递的是一个复杂类型,wsdl说明如下
- <wsdl:types>
- <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://202.105.212.146:8080/jboss-net/services/SendSMS">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
- <complexType name="ArrayOf_xsd_string">
- <complexContent>
- <restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]" />
</restriction>
</complexContent>
</complexType>
</schema>
</wsdl:types>
直接传String abc[]进去会返回异常java.lang.String cannot be cast to [Ljava.lang.String请问如何解决
最后是把数组表示为string,然后传入的。
2种情况
1)数组序列化的时候因为服务器端没有序列方法,所以不能正常解析为数组参数;
2)序列化后所有的参数都为null..追问
请问可以让我看看你的代码,数组如何表示为string嘛?
追答/**
* Mehtod to convert MNCDModel to a string to avoid array serialzation
* convertMNCDModelToStr
* @param model
* @return
* String
*/
public static String convertMNCDModelToStr(MajAAPS4MNCDModel model)
StringBuilder sb = new StringBuilder("[");
//Note: KEEP all field name UPPERCASE, in server side we MUST use equalsIgnoreCase() for safety
sb.append("START=").append(model.getStart());
sb.append(",");
sb.append("OFFSET=").append(model.getOffset());
sb.append(",");
sb.append("INQUIRYIDENTIFICATION=").append(model.getInquiryIdentification());
sb.append(",");
sb.append("APPLIACTIONNAME=").append(model.getAppliactionName());
sb.append(",");
sb.append("COUNTRYCODE=").append(model.getCountryCode());
sb.append(",");
我的数组里面封装的是对象,对象之间用[]分割,对象成员之间用,分割。。
数组序列化,就我那2天搜寻的结果是不可能实现的。所以可以考虑xml封装,或者橡 我 一样用string....
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.SOAPHTTPConnection;
public class testClient
public static void main(String[] args) throws Exception
URL url = new URL ("");
//改成你的地址
SOAPMappingRegistry smr = new SOAPMappingRegistry ();
StringDeserializer sd = new StringDeserializer ();
smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("", "Result"), null, null, sd);
// 创建传输路径和参数
SOAPHTTPConnection st = new SOAPHTTPConnection();
// 创建调用
Call call = new Call ();
call.setSOAPTransport(st);
call.setSOAPMappingRegistry (smr);
call.setTargetObjectURI ("");
call.setMethodName("addNumbers");
call.setEncodingStyleURI ("");
Vector params = new Vector();
params.addElement(new Parameter("NumberOne", Double.class, "10", null));
params.addElement(new Parameter("NumberTwo", Double.class, "25", null));
call.setParams(params);
Response resp = null;
try
resp = call.invoke (url, "");
catch (SOAPException e)
System.err.println("Caught SOAPException (" + e.getFaultCode () + "): " + e.getMessage ());
return;
// 检查返回值
if (resp != null && !resp.generatedFault())
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println ("Answer--> " + value);
else
Fault fault = resp.getFault ();
System.err.println ("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
你可以参考一下这个.
URL就是axis的地址 参考技术D import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import org.apache.soap.transport.http.SOAPHTTPConnection;
public class testClient
public static void main(String[] args) throws Exception
URL url = new URL ("");
//改成你的地址
SOAPMappingRegistry smr = new SOAPMappingRegistry ();
StringDeserializer sd = new StringDeserializer ();
smr.mapTypes (Constants.NS_URI_SOAP_ENC, new QName ("", "Result"), null, null, sd);
// 创建传输路径和参数
SOAPHTTPConnection st = new SOAPHTTPConnection();
// 创建调用
Call call = new Call ();
call.setSOAPTransport(st);
call.setSOAPMappingRegistry (smr);
call.setTargetObjectURI ("");
call.setMethodName("addNumbers");
call.setEncodingStyleURI ("");
Vector params = new Vector();
params.addElement(new Parameter("NumberOne", Double.class, "10", null));
params.addElement(new Parameter("NumberTwo", Double.class, "25", null));
call.setParams(params);
Response resp = null;
try
resp = call.invoke (url, "");
catch (SOAPException e)
System.err.println("Caught SOAPException (" + e.getFaultCode () + "): " + e.getMessage ());
return;
// 检查返回值
if (resp != null && !resp.generatedFault())
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println ("Answer--> " + value);
else
Fault fault = resp.getFault ();
System.err.println ("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
你可以参考一下这个.
URL就是axis的地址
本回答被提问者采纳
以上是关于webservice 接口用java中的axis调用,java编程传递一个参数String[]给网络接口为啥报错的主要内容,如果未能解决你的问题,请参考以下文章
请问达人,java 提供webservice接口,用XML传输数据,怎么实现?
我第一次接触webservice,怎么调用用web service接口,cxf或者axis2都行,网上找的例子,都有点错误