webservice 接口用java中的axis调用,java编程传递一个参数String[]给网络接口为什么报错
要传递的是一个复杂类型,wsdl说明如下-<wsdl:types>-<schemaxmlns="http://www.w3.org/2001/XMLSchema"targ...
要传递的是一个复杂类型,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请问如何解决 展开
- <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请问如何解决 展开
4个回答
展开全部
这个牵扯到数组序列化问题,前几天让我郁闷了好久。
最后是把数组表示为string,然后传入的。
2种情况
1)数组序列化的时候因为服务器端没有序列方法,所以不能正常解析为数组参数;
2)序列化后所有的参数都为null..
最后是把数组表示为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....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
大概是这么回事,你是直接把数组的内存地址传过去了,你看看这个schema被marshall出来的java类都有些什么属性,那个属性不见得是个数组。你用JAXB来做吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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的地址
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的地址
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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的地址
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的地址
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询