我是android应用的新手。我的任务是调用Web服务(使用SOAP)。我根据在互联网上找到的说明编写了代码。要序列化类,我正在使用ksoap2 ver。 3.4.0。该代码是在Android Studio中编写和测试的。调用网络服务后,我得到了:
java.lang.RuntimeException:无法序列化:“ +类名。
这是WSDL定义类的一部分。
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tns="http://wko.symlek.zeto.olsztyn.pl/SymlekService/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SymlekService" targetNamespace="http://wko.symlek.zeto.olsztyn.pl/SymlekService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema targetNamespace="http://wko.symlek.zeto.olsztyn.pl/SymlekService/">
<xsd:element name="ParametryPodajOstatniaProbe">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="nrStada" type="xsd:string" />
<xsd:element name="czyTworzyc" type="xsd:boolean" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="OboraOstProba">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" name="nrStada" type="xsd:string" />
<xsd:element minOccurs="0" maxOccurs="unbounded" name="nrObory" type="xsd:string" />
<xsd:element name="status" type="tns:StatusObory" />
<xsd:element minOccurs="0" name="dProby" type="xsd:date" />
<xsd:element minOccurs="0" name="metOc" type="xsd:byte" />
<xsd:element minOccurs="0" name="rodzProby" type="xsd:byte" />
<xsd:element minOccurs="0" name="godzBiezDoju" type="xsd:time" />
<xsd:element minOccurs="0" name="godzPoprzDoju" type="xsd:time" />
<xsd:element minOccurs="0" name="liczbaKrow" type="xsd:short" />
<xsd:element minOccurs="0" name="kodZoot1" type="xsd:string" />
<xsd:element minOccurs="0" name="kodZoot2" type="xsd:string" />
<xsd:element minOccurs="0" name="kodZoot3" type="xsd:string" />
<xsd:element minOccurs="0" name="kodZoot4" type="xsd:string" />
<xsd:element minOccurs="0" name="sumaMl" type="xsd:double" />
<xsd:element minOccurs="0" name="liczbaDojow" type="xsd:byte" />
<xsd:element minOccurs="0" name="liczbaKrowNieub" type="xsd:short" />
<xsd:element minOccurs="0" name="dataWprow" type="xsd:date" />
<xsd:element minOccurs="0" name="dataPrzyb" type="xsd:date" />
<xsd:element minOccurs="0" name="dataUb" type="xsd:date" />
<xsd:element minOccurs="0" maxOccurs="unbounded" name="krowy" type="tns:KrowaOstatniaProba" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="StatusObory">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="BEZ_KOREKTY" />
<xsd:enumeration value="PO_KOREKCIE" />
<xsd:enumeration value="BRAK_OBORY" />
<xsd:enumeration value="NIE_STADO" />
<xsd:enumeration value="NIE_PRZELICZONA" />
<xsd:enumeration value="NOWE_STADO" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="KrowaOstatniaProba">
<xsd:sequence>
<xsd:element minOccurs="1" name="nrObory" type="xsd:string" />
<xsd:element minOccurs="0" name="lp" type="xsd:short" />
<xsd:element minOccurs="0" name="kolczyk" type="xsd:string" />
<xsd:element minOccurs="0" name="nazwa" type="xsd:string" />
<xsd:element minOccurs="0" name="nrOborowy" type="xsd:int" />
<xsd:element minOccurs="0" name="nrGr" type="xsd:string" />
<xsd:element minOccurs="0" name="szybk" type="xsd:byte" />
<xsd:element minOccurs="0" name="temp" type="xsd:byte" />
<xsd:element minOccurs="0" name="wynikiWOstPr" type="tns:WynikiOstatniaProba" />
<xsd:element minOccurs="0" name="stanWOstPr" type="tns:StanOstatniaProba" />
<xsd:element minOccurs="0" name="poprzZd" type="tns:ZdarzeniaPoprzednie" />
<xsd:element minOccurs="0" name="ostPokr" type="tns:PokrycieOstatniaProba" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="WynikiOstatniaProba">
<xsd:sequence>
<xsd:element minOccurs="0" name="doj1" type="xsd:double" />
<xsd:element minOccurs="0" name="doj2" type="xsd:double" />
<xsd:element minOccurs="0" name="doj3" type="xsd:double" />
<xsd:element minOccurs="0" name="sumaMl" type="xsd:double" />
<xsd:element minOccurs="0" name="prTl" type="xsd:double" />
<xsd:element minOccurs="0" name="prBi" type="xsd:double" />
<xsd:element minOccurs="0" name="lakt" type="xsd:double" />
<xsd:element minOccurs="0" name="suchaM" type="xsd:double" />
<xsd:element minOccurs="0" name="komSom" type="xsd:long" />
<xsd:element minOccurs="0" name="moczn" type="xsd:long" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="StanOstatniaProba">
<xsd:sequence>
<xsd:element minOccurs="0" name="dPrzyb" type="xsd:date" />
<xsd:element minOccurs="0" name="kodPrzyb" type="xsd:byte" />
<xsd:element minOccurs="0" name="dUb" type="xsd:date" />
<xsd:element minOccurs="0" name="kodUb" type="xsd:byte" />
<xsd:element minOccurs="0" name="kodCh" type="xsd:byte" />
<xsd:element minOccurs="0" name="dZas" type="xsd:date" />
<xsd:element minOccurs="0" name="kontZas" type="xsd:string" />
<xsd:element minOccurs="0" name="dWyc" type="xsd:date" />
<xsd:element minOccurs="0" name="kodPor" type="xsd:byte" />
<xsd:element minOccurs="0" name="nrLakt" type="xsd:byte" />
<xsd:element minOccurs="0" name="prognozowaneZdarzenie" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ZdarzeniaPoprzednie">
<xsd:sequence>
<xsd:element minOccurs="0" name="dOstWyc" type="xsd:date" />
<xsd:element minOccurs="0" name="nrOstLakt" type="xsd:byte" />
<xsd:element minOccurs="0" name="lCielWOstWyc" type="xsd:byte" />
<xsd:element minOccurs="0" name="etWOstWyc" type="xsd:string" />
<xsd:element minOccurs="0" name="kodOstWyc" type="xsd:byte" />
<xsd:element minOccurs="0" name="dOstZas" type="xsd:date" />
<xsd:element minOccurs="0" name="dOstUb" type="xsd:date" />
<xsd:element minOccurs="0" name="dOstPrzyb" type="xsd:date" />
<xsd:element minOccurs="0" name="kodOstPrzyb" type="xsd:byte" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="PokrycieOstatniaProba">
<xsd:sequence>
<xsd:element name="nrBuh" type="xsd:string" />
<xsd:element minOccurs="0" name="nazwaBuh" type="xsd:string" />
<xsd:element minOccurs="0" name="dPokr" type="xsd:date" />
<xsd:element minOccurs="0" name="kodPokr" type="xsd:byte" />
<xsd:element minOccurs="0" name="dPokrDo" type="xsd:date" />
</xsd:sequence>
</xsd:complexType>
...
<wsdl:message name="podajOstatniaProbeRequest">
<wsdl:part name="parametry" element="tns:ParametryPodajOstatniaProbe" />
</wsdl:message>
...
<wsdl:binding name="symlekServiceSOAP" type="tns:symlekService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="podajOstatniaProbe">
<soap:operation soapAction="http://wko.symlek.zeto.olsztyn.pl/SymlekService/podajOstatniaProbe" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
我的基于Kvmserializable的类:
package pl.pfhb.fernandomobile.transWS;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import java.util.Hashtable;
public class ParametryPodajOstatniaProbe implements KvmSerializable{
protected String nrStada;
protected Boolean czyTworzyc=false;
public String getNrStada(){
return nrStada;
}
public void setNrStada(String value) {
this.nrStada = value;
}
public boolean isCzyTworzyc() {
return czyTworzyc;
}
public void setCzyTworzyc(boolean value) {
this.czyTworzyc = value;
}
@Override
public Object getProperty(int index)
{
switch(index){
case 0:
return nrStada;
case 1:
return czyTworzyc;
default:
return null;
}
}
@Override
public void setProperty(int index, Object value){
switch(index){
case 0:
nrStada=value.toString();
break;
case 1:
czyTworzyc=(Boolean)czyTworzyc;
break;
default:
break;
}
}
@Override
public void setInnerText(String value) {
//need by compiler
}
@Override
public String getInnerText(){
//need by compiler
}
@Override
public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info){
switch(index){
case 0:
info.type=PropertyInfo.STRING_CLASS;
info.name="nrStada";
break;
case 1:
info.type=PropertyInfo.BOOLEAN_CLASS;
info.name="czyTworzyc";
break;
default:
break;
}
}
@Override
public int getPropertyCount(){
return 2;
}
}
package pl.pfhb.fernandomobile.transWS;
import android.os.AsyncTask;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import pl.pfhb.fernandomobile.transWS.ParametryPodajOstatniaProbe;
public class symServ {
private static final String NAMESPACE="http://wko.symlek.zeto.olsztyn.pl/SymlekService/";
private static final String URL="https://217.153.203.98/SymlekWS/services/symlekService/";
public void pop(ParametryPodajOstatniaProbe param) {
webServCall ws=new webServCall();
ws.execute(param);
}
public class webServCall extends AsyncTask<ParametryPodajOstatniaProbe, Void, Void> {
@Override
protected Void doInBackground(ParametryPodajOstatniaProbe... param){
if(android.os.Debug.isDebuggerConnected())
android.os.Debug.waitForDebugger();
final String SOAP_ACTION = "http://wko.symlek.zeto.olsztyn.pl/SymlekService/podajOstatniaProbe";
final String METHOD_NAME = "podajOstatniaProbe";
SoapObject soapObj = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("ParametryPodajOstatniaProbe");
pi.setValue(param);
pi.setType(new ParametryPodajOstatniaProbe().getClass());
soapObj.addProperty(pi);
SoapSerializationEnvelope soapEnv = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnv.dotNet = true;
soapEnv.setOutputSoapObject(soapObj);
soapEnv.addMapping(NAMESPACE, "ParametryPodajOstatniaProbe", new ParametryPodajOstatniaProbe().getClass());
HttpTransportSE ht = new HttpTransportSE(URL);
ht.debug = true;
try {
ht.call(SOAP_ACTION, soapEnv);
} catch (Exception e) {
//for test
String s = e.getMessage().toString();
//java.lang.RuntimeException: Cannot serialize: [Lpl.pfhb.fernandomobile.transWS.ParametryPodajOstatniaProbe;@f1d6c65
}
return null;
}
@Override
protected void onPreExecute(){
//later
}
}
}
在用kotlin编写的按钮代码中使用了类(已经在前面编写过):
var tr: symServ = symServ()
var pr:ParametryPodajOstatniaProbe= ParametryPodajOstatniaProbe()
pr.nrStada="4111111";
if(!pr.isCzyTworzyc()){
pr.isCzyTworzyc=true
}
tr.pop(pr)
我想向您寻求帮助。我有3个问题:
数据在soapObj中(调试)。通过ht.call(SOAP_ACTION,soapEnv)调用Web服务之后;我收到错误“ java.lang.RuntimeException:无法序列化:[Lpl.pfhb.fernandomobile.transWS.ParametryPodajOstatniaProbe; @ f1d6c65”-我在做什么错了?
Web服务需要通过用户名和密码进行授权。没有HttpTransportBasicAuth(如手册中所述)。如何将它们传递给Web服务?
已经编写了OboraOstProba类(长代码)如何捕获ht的响应并将其放入OboraOstProba类中? 预先感谢。