使用KSoap库消耗.NET Web服务时出错

时间:2013-02-15 12:27:53

标签: android ksoap

我一直在使用kso​​ap库来使用.net web服务。 我收到了这种错误

  

“预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}信封(位置:START_TAG @ 1:7 in java.io.InputStreamReader@40d0c7d8)”

我搜遍了所有地方,但找不到任何好的帮助。

以下是我尝试使用Web服务的代码。

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

}

2 个答案:

答案 0 :(得分:1)

尝试获得更好的代码。你的代码听起来有点笨拙。

  

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

这个。

  1. 使用.netcode

  2. 检查您的methodname和url
  3. 排除C#appcode文件中的app_html.offline,因为它不允许任何数据库项目运行。

  4. 希望它能帮到你。

答案 1 :(得分:0)

我也遇到了这个错误。最终,它通过设置这些值得到修复:

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

其中,192.168.1.3是我当地的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>