KSOAP 生成的 SOAP 请求不会导致任何错误但无法正常工作

KSOAP generated SOAP request don't cause any error but not working

这是我的问题:

由 KSOAP2 3.6.1 生成 android:不会导致任何 XML/SOAP 错误,但 Web 服务在数据库中将 0 记录为 IdMaquina。插入的值是错误的(这不是我发送的值)。网络服务响应正常。


<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    <v:Header />
    <v:Body>
        <IngresarMaquinaLog xmlns="http://tempuri.org/">
            <maquinaLog>
                 <IdMaquina>123</IdMaquina>
            </maquinaLog>
        </IngresarMaquinaLog>
    </v:Body>
</v:Envelope>

由 Boomrang chrome 插件生成:工作正常。插入数据库的值是正确的(它等于我发送的值)。网络服务响应正常。


<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:obe="http://schemas.datacontract.org/2004/07/myService.Entidades">
    <x:Header/>
    <x:Body>
        <tem:IngresarMaquinaLog>
            <tem:maquinaLog>
                <obe:IdMaquina>4567</obe:IdMaquina>
            </tem:maquinaLog>
        </tem:IngresarMaquinaLog>
    </x:Body>
</x:Envelope>

用作 maquinaLog 定义:

{ public class maquinaLog 实现了 KvmSerializable { public int IdMaquina;</p> <pre><code> public maquinaLog(){} public maquinaLog(int idMaquinaField) { IdMaquina = idMaquinaField; } public Object getProperty(int arg0) { switch(arg0) { case 0: return IdMaquina; } return null; } public int getPropertyCount() { return 1; } public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) { switch(index) { case 0: info.type = PropertyInfo.INTEGER_CLASS; info.name = "IdMaquina"; break; default:break; } } public void setProperty(int index, Object value) { switch(index) { case 0: IdMaquina = Integer.parseInt(value.toString()); break; default: break; } } } } </code>

用于构建 SOAP 请求: { public void WebServiceCallExample(整数 idmaquina) { 字符串名称空间 = "<a href="http://tempuri.org/" rel="nofollow">http://tempuri.org/</a>"; 字符串 METHOD_NAME = "IngresarMaquinaLog"; 字符串 SOAP_ACTION = 命名空间 + "IMyService/IngresarMaquinaLog"; 字符串 URL = "<a href="http://MyUrl/MyService/MyService.svc" rel="nofollow">http://MyUrl/MyService/MyService.svc</a>";</p> <pre> SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.implicitTypes = true; envelope.setAddAdornments(false); maquinaLog ML = new maquinaLog(); ML.IdMaquina = idmaquina; PropertyInfo pi = new PropertyInfo(); pi.setName("maquinaLog"); pi.setNamespace(NAMESPACE); pi.setValue(ML); pi.setType(ML.getClass()); request.addProperty(pi); envelope.setOutputSoapObject(request); envelope.addMapping(NAMESPACE, "maquinaLog",new maquinaLog().getClass()); androidHttpTransport.debug = true; try { //Log.i("app", androidHttpTransport.requestDump); androidHttpTransport.call(SOAP_ACTION, envelope); Log.i("appRQS", androidHttpTransport.requestDump); Log.i("appRSP", androidHttpTransport.responseDump); } catch(Exception e) { e.printStackTrace(); } } }

我终于成功匹配了 Boomrang chrome 插件查询。

在我添加的复杂对象定义中: </p> <pre><code>public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) { switch(index) { case 0: info.type = PropertyInfo.INTEGER_CLASS; info.name = "obe:IdMaquina"; break; default:break; } }

并且我在信封中添加了一个属性: </p> <pre><code>PropertyInfo pi = new PropertyInfo(); pi.setName("maquinaLog"); pi.setNamespace(NAMESPACE); pi.setValue(ML); pi.setType(ML.getClass()); request.addProperty(pi); request.addAttribute("xmlns:obe","http://schemas.datacontract.org/2004/07/OberthurService.Entidades");