ksoap2 - 请求参数设置为null

时间:2013-06-27 07:03:31

标签: android ksoap2 android-ksoap2

当我从Android调用我的webservice函数时,设置params时遇到问题,但是在web中它可以正常工作。

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

我使用Jboss挂载我的服务器,这是我从中删除其他函数的web服务,以使其更容易理解:

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

注意:我检查我的服务器日志,他得到的参数是null(该函数是调用但是为null)。

1 个答案:

答案 0 :(得分:1)

像这样使用。

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

将此用于Reference。希望这会对你有所帮助。