首页 文章

KSOAP生成的SOAP请求不会导致任何错误但不起作用

提问于
浏览
0

这是我的问题:

由KSOAP2生成3.6.1 android:不要在数据库中导致任何XML / SOAP错误,但webservice记录0为IdMaquina . 插入的值是错误的(它不是我发送的值) . Web服务响应没问题 .

<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插件生成:工作正常 . 插入数据库中的值是正确的(它等于我发送的值) . Web服务响应没问题 .

<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>

使用as maquinaLog定义:

{ public class maquinaLog implements KvmSerializable { public int IdMaquina;
`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>
Using to build SOAP request: { public void WebServiceCallExample(Integer idmaquina) { String NAMESPACE = "http://tempuri.org/"; String METHOD_NAME = "IngresarMaquinaLog"; String SOAP_ACTION = NAMESPACE + "IMyService/IngresarMaquinaLog"; String URL = "http://MyUrl/MyService/MyService.svc";`

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();
    }

}
}

1 回答

  • 1

    最后,我成功地匹配了Boomrang chrome插件查询 .

    在复杂的对象定义中,我添加了: `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; } }`

    我已经为enveloppe添加了一个属性: `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");`

相关问题