gpt4 book ai didi

android - 在 ksoap2 android 中找不到类型错误的解串器

转载 作者:行者123 更新时间:2023-11-30 02:53:04 33 4
gpt4 key购买 nike

我想在 android 中使用 ksoap2 将类作为参数发送到 Web 服务。这是我在 android 中的代码:

public Object simpleConnect() {
SoapObject request = new SoapObject(namespace, methodName);

Foo para = new Foo();
para.setFooId(2333222);
para.setCompanyId(12);
para.setField2(true);
para.setField3(2);
para.setPrimaryKey(765);
para.setUserId(987);

request.addProperty("param", para);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);
envelope.addMapping(namespace, "Foo", Foo.class);

HttpTransportSE ht = new HttpTransportSE(url);
try {
ht.call(soapAction, envelope);

return envelope.getResponse(); //got error deserialize in this line
} catch (Exception e) {
e.printStackTrace();
}

return null;
}

这是我在服务中尝试调用的方法:

public Foo addObjFoo(Foo param) throws SystemException {

System.out.println("something");

fooPersistence.update(param, false);

return param;
}

这是我的 wsdl:

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:http.service.test.com" xmlns:intf="urn:http.service.test.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://model.test.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:http.service.test.com">
<!--WSDL created by Apache Axis version: 1.4Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://model.test.com">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="FooSoap">
<sequence>
<element name="companyId" type="xsd:long"/>
<element name="field2" type="xsd:boolean"/>
<element name="field3" type="xsd:int"/>
<element name="fooId" type="xsd:long"/>
<element name="primaryKey" type="xsd:long"/>
<element name="userId" type="xsd:long"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="addFooResponse">
<wsdl:part name="addFooReturn" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="printmessageRequest">
<wsdl:part name="behi" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="addFooRequest">
<wsdl:part name="para" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="printmessageResponse">
<wsdl:part name="printmessageReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="addObjFooResponse">
<wsdl:part name="addObjFooReturn" type="tns1:FooSoap"/>
</wsdl:message>
<wsdl:message name="addObjFooRequest">
<wsdl:part name="param" type="xsd:anyType"/>
</wsdl:message>
<wsdl:portType name="FooServiceSoap">
<wsdl:operation name="addFoo" parameterOrder="para">
<wsdl:input message="impl:addFooRequest" name="addFooRequest"/>
<wsdl:output message="impl:addFooResponse" name="addFooResponse"/>
</wsdl:operation>
<wsdl:operation name="addObjFoo" parameterOrder="param">
<wsdl:input message="impl:addObjFooRequest" name="addObjFooRequest"/>
<wsdl:output message="impl:addObjFooResponse" name="addObjFooResponse"/>
</wsdl:operation>
<wsdl:operation name="printmessage" parameterOrder="behi">
<wsdl:input message="impl:printmessageRequest" name="printmessageRequest"/>
<wsdl:output message="impl:printmessageResponse" name="printmessageResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Plugin_obtice_FooServiceSoapBinding" type="impl:FooServiceSoap">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="addFoo">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addFooRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:http.service.test.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="addFooResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:http.service.test.com" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="addObjFoo">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addObjFooRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:http.service.test.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="addObjFooResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:http.service.test.com" use="encoded"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="printmessage">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="printmessageRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:http.service.test.com" use="encoded"/>
</wsdl:input>
<wsdl:output name="printmessageResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:http.service.test.com" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="FooServiceSoapService">
<wsdl:port binding="impl:Plugin_obtice_FooServiceSoapBinding" name="Plugin_obtice_FooService">
<wsdlsoap:address location="http://localhost:8080/WebService-portlet/axis/Plugin_obtice_FooService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

最后这是我在客户端的 Foo 类:

package com.obtice.liferaytest;

import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

public class Foo implements KvmSerializable {

protected long localCompanyId;

public long getCompanyId() {
return localCompanyId;
}

public void setCompanyId(long param) {
this.localCompanyId = param;
}


protected boolean localField2;

public boolean getField2() {
return localField2;
}

public void setField2(boolean param) {
this.localField2 = param;
}


protected int localField3;

public int getField3() {
return localField3;
}

public void setField3(int param) {
this.localField3 = param;
}


protected long localFooId;

public long getFooId() {
return localFooId;
}

public void setFooId(long param) {
this.localFooId = param;
}


protected long localPrimaryKey;

public long getPrimaryKey() {
return localPrimaryKey;
}

public void setPrimaryKey(long param) {
this.localPrimaryKey = param;
}


protected long localUserId;

public long getUserId() {
return localUserId;
}

public void setUserId(long param) {
this.localUserId = param;
}


@Override
public Object getProperty(int index) {

Object object = null;

switch (index) {
case 0:
object = localCompanyId;
break;
case 1:
object = localField2;
break;
case 2:
object = localField3;
break;
case 3:
object = localFooId;
break;
case 4:
object = localPrimaryKey;
break;
case 5:
object = localUserId;
break;

default:
break;
}
return object;
}

@Override
public int getPropertyCount() {
return 9;
}

@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {

switch (index) {
case 0:
info.name = "companyId" ;
info.type = PropertyInfo.LONG_CLASS ;
break;
case 1:
info.name = "field2";
info.type = PropertyInfo.BOOLEAN_CLASS ;
break;
case 2:
info.name = "field3";
info.type = PropertyInfo.INTEGER_CLASS ;
break;
case 3:
info.name = "fooId";
info.type = PropertyInfo.LONG_CLASS ;
break;
case 4:
info.name = "primaryKey";
info.type = PropertyInfo.LONG_CLASS ;
break;
case 5:
info.name = "userId";
info.type = PropertyInfo.LONG_CLASS ;
break;

default:
break;
}
}

@Override
public void setProperty(int index, Object obj) {
String objStr = obj.toString();

switch (index) {
case 0:
localCompanyId = Long.parseLong(objStr);
break;
case 1:
localField2 = Boolean.parseBoolean(objStr);
break;
case 2:
localField3 = Integer.parseInt(objStr);
break;
case 3:
localFooId = Long.parseLong(objStr);
break;
case 4:
localPrimaryKey = Long.parseLong(objStr);
break;
case 5:
localUserId = Long.parseLong(objStr);
break;

default:
break;
}
}
}

我在调用 Web 服务和响应时遇到了这个错误:

SoapFault - faultcode: 'soapenv:Server.userException' faultstring: 'org.xml.sax.SAXException: Deserializing parameter 'param':  could not find deserializer for type {urn:http.service.test.com/}Foo' faultactor: 'null' detail: org.kxml2.kdom.Node@4057bb40

请帮帮我。我完全坚持了下来。

谢谢...

最佳答案

我收到了同样的错误消息,我正在疯狂地试图找出答案。

在传输调用之前添加这一行

androidHttpTransport.debug = true;

通话后的这两个

Log.i(REQUEST, androidHttpTransport.requestDump); 
Log.i(RESPONSE, androidHttpTransport.responseDump);

并查看您在信封中发送的 Foo 的类型,并确保它与 WSDL 中声明的类型相匹配。

在我的项目中,原来是包络映射

envelope.addMapping(namespace, "GetFacilityReservations",GetFacilityReservations.class);

将我的自定义类作为类型 n0 发送,因为那是我最初声明的 namespace 的类型。但是我的类(class)是另一种类型。

所以我需要做的就是在我的映射中将命名空间更改为正确的。

envelope.addMapping("urn:XPressLocate", "GetFacilityReservations",GetFacilityReservations.class);

关于android - 在 ksoap2 android 中找不到类型错误的解串器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23803577/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com