Getting error when using KSoap library to consume

2019-07-21 11:17发布

问题:

I have been using ksoap library to consume .net web service. and I am getting this kind of error

"expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @1:7 in java.io.InputStreamReader@40d0c7d8)"

I have searched every where but I couldn't find any good help.

Here is the code where I try to consume the web service.

public class WebInvoke {

    private static final String NAMESPACE = "http://tempuri.org/" ;
    private static final String METHOD_NAME = "login";
    private static final String SOAP_ACTION = NAMESPACE + METHOD_NAME;
    private static final String URL = "http://10.0.2.2/Service1.asmx";
    private final SoapSerializationEnvelope envelope;


    public WebInvoke()
    {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        PropertyInfo quotesProperty = new PropertyInfo();
        quotesProperty.setName("UserName");
        quotesProperty.setValue("admin");
        quotesProperty.setType(String.class);
        request.addProperty(quotesProperty);

        quotesProperty = new PropertyInfo();
        quotesProperty.setName("Password");
        quotesProperty.setValue("a");
        quotesProperty.setType(String.class);
        request.addProperty(quotesProperty);

        Log.e("Request Assign", request.toString());
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        Log.e("Envelope Assign", envelope.toString());
    }
    public String Fetch()
    {
        String result = "";
        HttpTransportSE httpRequest = new HttpTransportSE(URL);
        try
        {
            envelope.xsd = SoapSerializationEnvelope.XSD;
            envelope.enc = SoapSerializationEnvelope.ENC;

            httpRequest.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

             Log.e("httpRequest.call", "httpRequest.call");
            httpRequest.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            result =  response.toString();
        }
        catch(Exception e)
        {
            //e.printStackTrace();
            Log.e("httpRequest.call Exception", e.getMessage());
        }
        return result;
    }

}

回答1:

Try and get a better code. Your code sounds a bit clumsy.

"org.xmlpull.v1.XmlPullParserException: expected: START_TAG" Error expected-start-tag-error

chk this.

  1. Check your methodname and url with .netcode

  2. Exclude the app_html.offline in C# appcode file as it won’t allow any database project to run.

hope it helps ya.



回答2:

I also got this error. Ultimately, it got fixed by setting these values:

String SOAP_ACTION = "BookTypeService";

String METHOD_NAME = "bookType";

String NAMESPACE = "http://192.168.1.3:8080/MyWebService/services/";

String URL = "http://192.168.1.3:8080/MyWebService/services/BookTypeService";

where, 192.168.1.3 is my local I/P.

<wsdl:service name="BookTypeServiceService">
<wsdl:port name="BookTypeService" binding="impl:BookTypeServiceSoapBinding">
<wsdlsoap:address location="http://localhost:8080/MyWebService/services/BookTypeService"/>
</wsdl:port>
</wsdl:service>


标签: android ksoap