【问题标题】:ksoap2 - request parameters is set nullksoap2 - 请求参数设置为空
【发布时间】:2013-06-27 07:03:30
【问题描述】:

当我从 Android 调用我的 web 服务函数时,我在设置参数时遇到了问题,但是在 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>

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

【问题讨论】:

    标签: android ksoap2 android-ksoap2


    【解决方案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。希望这会对你有所帮助。

    【讨论】:

    • 它不起作用,一切都很好,它不起作用。 :( 错误可能与字符编码有关?
    • 您是否传递了正确的 NAMESPACE、METHOD_NAME 和 SOAP_ACTION。?
    • 我不知道我做了什么,但现在可以了,哈哈。我必须更改 SoapPrimitive 而不是 SObject。所以我标记为好的回复。
    • @ƒernandoValle 我认为有同样的问题......你是怎么解决的?
    猜你喜欢
    • 1970-01-01
    • 2017-05-08
    • 2016-09-06
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多