Ошибка выполнения при getResponse с использованием Android KSOAP - PullRequest
0 голосов
/ 05 мая 2011

Мой Android получает ошибку во время выполнения в SoapObject result = (SoapObject) envelope.getResponse ();Веб-сервис находится в моем ноутбуке (192.168.15.13), ноутбук и Android подключены через локальную сеть.Я создал веб-сервис, используя Axis2 в Knopflerfish OSGi.Вот мой код:

package test.msani.aksessoap;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class TesAksesSOAP extends Activity {
    private static final String SOAP_ACTION = "SOAPObjectSani.SOAPObjectSani/SOAPObjectSani/getKeterangan";
    private static final String METHOD_NAME = "getKeterangan";
    private static final String NAMESPACE = "SOAPObjectSani.SOAPObjectSani/SOAPObjectSani";
    private static final String URL = "http://192.168.15.13:8080/axis2/services/SOAPObjectSani";
    TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        //set parameter
        PropertyInfo pi = new PropertyInfo();
        pi.setName("angka");
        pi.setValue(2);
        pi.setType(int.class);
        request.addProperty(pi);

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

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        Log.i("Sani", "coming 1");

        try {
            Log.i("Sani", "coming 2");
            androidHttpTransport.call(SOAP_ACTION, envelope);
            Log.i("Sani", "coming 3");
        } catch (IOException e) {
            tv.setText("IOException");
        } catch (XmlPullParserException e) {
            tv.setText("XmlPullParserException");
        }

        SoapObject result = null;
        try {
            Log.i("Sani", "coming 4");
            result = (SoapObject)envelope.getResponse(); //I get the error here
            Log.i("Sani", "coming 5");
        } catch (SoapFault e) {
            tv.setText("SoapFault");
        }

        //to get the data
        String resultData = result.getProperty(0).toString();

        tv.setText("" + resultData);

        setContentView(tv);
    }
}

, а вот WSDL

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="SOAPObjectSani.SOAPObjectSani/SOAPObjectSani" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="SOAPObjectSani.SOAPObjectSani/SOAPObjectSani">
    <wsdl:types>
        <xs:schema xmlns:ns="SOAPObjectSani.SOAPObjectSani/SOAPObjectSani" attributeFormDefault="qualified" elementFormDefault="unqualified" targetNamespace="SOAPObjectSani.SOAPObjectSani/SOAPObjectSani">
            <xs:element name="getTanggalSpesial">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="peristiwa" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="getTanggalSpesialResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="getKeterangan">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="angka" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="getKeteranganResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="getKeteranganRequest">
        <wsdl:part name="parameters" element="ns0:getKeterangan"/>
    </wsdl:message>
    <wsdl:message name="getKeteranganResponse">
        <wsdl:part name="parameters" element="ns0:getKeteranganResponse"/>
    </wsdl:message>
    <wsdl:message name="getTanggalSpesialRequest">
        <wsdl:part name="parameters" element="ns0:getTanggalSpesial"/>
    </wsdl:message>
    <wsdl:message name="getTanggalSpesialResponse">
        <wsdl:part name="parameters" element="ns0:getTanggalSpesialResponse"/>
    </wsdl:message>
    <wsdl:portType name="SOAPObjectSaniPortType">
        <wsdl:operation name="getKeterangan">
            <wsdl:input message="ns0:getKeteranganRequest" wsaw:Action="urn:getKeterangan"/>
            <wsdl:output message="ns0:getKeteranganResponse" wsaw:Action="urn:getKeteranganResponse"/>
        </wsdl:operation>
        <wsdl:operation name="getTanggalSpesial">
            <wsdl:input message="ns0:getTanggalSpesialRequest" wsaw:Action="urn:getTanggalSpesial"/>
            <wsdl:output message="ns0:getTanggalSpesialResponse" wsaw:Action="urn:getTanggalSpesialResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="SOAPObjectSaniSOAP11Binding" type="ns0:SOAPObjectSaniPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="getKeterangan">
            <soap:operation soapAction="urn:getKeterangan" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="getTanggalSpesial">
            <soap:operation soapAction="urn:getTanggalSpesial" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="SOAPObjectSaniSOAP12Binding" type="ns0:SOAPObjectSaniPortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="getKeterangan">
            <soap12:operation soapAction="urn:getKeterangan" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="getTanggalSpesial">
            <soap12:operation soapAction="urn:getTanggalSpesial" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="SOAPObjectSaniHttpBinding" type="ns0:SOAPObjectSaniPortType">
        <http:binding verb="POST"/>
        <wsdl:operation name="getKeterangan">
            <http:operation location="SOAPObjectSani/getKeterangan"/>
            <wsdl:input>
                <mime:content type="text/xml" part="getKeterangan"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="getKeterangan"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="getTanggalSpesial">
            <http:operation location="SOAPObjectSani/getTanggalSpesial"/>
            <wsdl:input>
                <mime:content type="text/xml" part="getTanggalSpesial"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="getTanggalSpesial"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="SOAPObjectSani">
        <wsdl:port name="SOAPObjectSaniSOAP11port_http" binding="ns0:SOAPObjectSaniSOAP11Binding">
            <soap:address location="http://0.0.0.0:8080/axis2/services/SOAPObjectSani"/>
        </wsdl:port>
        <wsdl:port name="SOAPObjectSaniSOAP12port_http" binding="ns0:SOAPObjectSaniSOAP12Binding">
            <soap12:address location="http://0.0.0.0:8080/axis2/services/SOAPObjectSani"/>
        </wsdl:port>
        <wsdl:port name="SOAPObjectSaniHttpport" binding="ns0:SOAPObjectSaniHttpBinding">
            <http:address location="http://0.0.0.0:8080/axis2/services/SOAPObjectSani"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

помогите мне, пожалуйста ...

1 Ответ

4 голосов
/ 05 мая 2011

Используйте эту строку

 response = (SoapObject) envelope.bodyIn;

Вместо

result = (SoapObject)envelope.getResponse();
...