KSOAP2了java.lang.RuntimeException:无法序列 [英] KSOAP2 java.lang.RuntimeException: Cannot serialize
问题描述
我想从.NET Web服务使用的方法。
I am trying to use a method from a .net web service.
背后的Web服务的code有一个'/'在命名空间的结尾
The code behind for the web service has a '/' at the end of the namespace
[WebService(Namespace = "http://www.mynamespace.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
下面是.NET方法调用
Here is the .net method call
POST /TelematicsWebService/Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.mynamespace.com/GetDevicesByBranch"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetDevicesByBranch xmlns="http://www.mynamespace.com/">
<branchNumber>int</branchNumber>
</GetDevicesByBranch>
</soap:Body>
</soap:Envelope>
现在的code调用该方法看起来像这样
Now the code calling the method looks like this
@Override
protected SoapObject doInBackground(Integer... branchNumber) {
final String NAMESPACE = "http://www.mynamespace.com/";
final String METHOD_NAME = "GetDevicesByBranch";
final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
final String URL = "http://10.0.2.2/TelematicsWebService/Service.asmx";
SoapObject response = null;
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo inputArgs = new PropertyInfo();
inputArgs.setName("branchNumber");
inputArgs.setValue(branchNumber);
inputArgs.setType(Integer.class);
request.addProperty(inputArgs);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,
25000);
androidHttpTransport.call(SOAP_ACTION, envelope);
response = (SoapObject) envelope.getResponse();
} catch (Exception exception) {
response = null;
}
return response;
}
接近尾声行, androidHttpTransport.call(SOAP_ACTION,包);
,抛出一个异常:了java.lang.RuntimeException:无法序列:[Ljava.lang.Integer; @ 412e0cf0
The line towards the end, androidHttpTransport.call(SOAP_ACTION, envelope);
, throws an exception: java.lang.RuntimeException: Cannot serialize: [Ljava.lang.Integer;@412e0cf0
我不能找到一个解决这个问题,有什么建议?
I can't find a solution to this issue, any suggestions?
推荐答案
我想它了...
这是内部的AsyncTask的&LT;>(),如果它是不是已经很明显的覆盖doInBackground()方法。输入参数是一个整数...
键入
This is inside an AsyncTask<>() if it wasn't already obvious with the Override doInBackground() method. The input parameter is a Integer...
type.
protected SoapObject doInBackground(Integer... branchNumber)
我不知道到底是省略号做究竟是什么,但我知道它使参数数组。
I don't know exactly what the ellipsis does exactly, but I know it makes the parameter an array.
我是路过一个整数数组复制到请求对象,而不是一个具体的数组元素。
I was passing an integer array into the request object rather than a specific array element.
改变从
request.addProperty("branchNumber", branchNumber);
到
request.addProperty("branchNumber", branchNumber[0]);
固定的问题。
fixed the issue.
感谢您@保罗 - 扬和@beginner!我AP preciate你的答案!
Thank you @Paul-Jan and @beginner! I appreciate your answers!
这篇关于KSOAP2了java.lang.RuntimeException:无法序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!