ksoap2 - request parameters is set null

半世苍凉 提交于 2019-12-11 19:23:29

问题


I have a problem setting the params when I call my webservice function from Android, however in web it works fine.

private static String URL="http://1.2.3.4:8080/Servidor/servicioTraducir?wsdl";
private static final String METHOD_NAME = "obtenerURL";
private static final String NAMESPACE = "http://servicioTraducir/"; 
private static final String SOAP_ACTION ="servicioTraducirService"; 
.
.
.
        request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("descripcion","hola.");

        //I tried with it too:
        //PropertyInfo texto = new PropertyInfo();
        //texto.setName("descripcion");
        //texto.setValue("hola.");
        //texto.setType("string".getClass());
        //request.addProperty(texto);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true; 
        envelope.setOutputSoapObject(request);

        HttpTransportSE transporte = new HttpTransportSE(URL);
        transporte.debug = true;  

        try {
            transporte.call(SOAP_ACTION, envelope);
            SoapObject result = (SoapObject)envelope.getResponse();
            String res = result.toString();

            urlResult = res;            


        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }

I mount my server with Jboss, this is the webservice that I have from which I delete other functions in for make it more understandable:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://servicioTraducir/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="servicioTraducirService" targetNamespace="http://servicioTraducir/">
<types>
    <xs:schema xmlns:tns="http://servicioTraducir/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://servicioTraducir/" version="1.0">
    <xs:element name="obtenerURL" type="tns:obtenerURL"/>
    <xs:complexType name="inicializarResponse">
        <xs:sequence>
            <xs:element minOccurs="0" name="return" type="xs:boolean"/>
            <xs:complexType name="obtenerURL">
        <xs:sequence>
    <xs:element minOccurs="0" name="descripcion" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>

    <xs:complexType name="obtenerURLResponse">...</xs:complexType>
    </xs:schema>
</types>
<message name="servicioTraducir_obtenerURL">
    <part element="tns:obtenerURL" name="obtenerURL"/>
</message>
<portType name="servicioTraducir">
    <operation name="obtenerURL" parameterOrder="obtenerURL">
        <input message="tns:servicioTraducir_obtenerURL"/>
        <output message="tns:servicioTraducir_obtenerURLResponse"/>
    </operation>
</portType>
<binding name="servicioTraducirBinding" type="tns:servicioTraducir">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="obtenerURL">
        <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
    </operation>
</binding>
<service name="servicioTraducirService">
    <port binding="tns:servicioTraducirBinding" name="servicioTraducirPort">
        <soap:address location="http://......:8080/Servidor/servicioTraducir"/>
    </port>
</service>

NOTE: I check in my server log and the param that he get is null (the function is call but with null).


回答1:


Use like this.

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);  
           request.addProperty("descripcion","hola."); 

 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
 envelope.setOutputSoapObject(request);

 HttpTransportSE ht = new HttpTransportSE(URL);
 ht.call(SOAP_ACTION, envelope);

 final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
 final String str = response.toString();

Use this for your Reference. Hope this will help you.



来源:https://stackoverflow.com/questions/17336651/ksoap2-request-parameters-is-set-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!