0

当我从 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>

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

4

1 回答 1

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

将此作为您的参考。希望这会帮助你。

于 2013-06-27T07:36:08.520 回答