尝试连接到 Web 服务 GetCountryByCountryCode 时出现 XmlPullParserException

发布于 2024-11-08 02:02:53 字数 2788 浏览 1 评论 0原文

我在尝试连接到网络服务时收到此输出

org.xmlpull.v1.XmlPullParserException: 意外类型(位置:END_DOCUMENT null@1:0 i[0.0] n java.io.InputStreamReader@6cf4fb80)

package com.rim.SoapRequest;

import net.rim.device.api.io.parser.soap.SOAPBody;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;

public class TSOAPRequest
{   

    public String fnSendRequest(String strServerUrl,String strServiceNamespace,String strSoapAction,String strMethodName,String strLablelText)
    {
        System.out.println("inside method !!!!!!!!");

        String strRequestData = "";

        SoapObject oSoapObject = new SoapObject(strServiceNamespace, strMethodName);
        SoapSerializationEnvelope oSoapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//      oSoapObject.addProperty("GetCountryByCountryCode",strLablelText);
        oSoapObject.addProperty("CountryCode",strLablelText);
        oSoapEnvelope.bodyOut = oSoapObject;
        oSoapEnvelope.dotNet = true;
        oSoapEnvelope.encodingStyle = SoapSerializationEnvelope.XSD;
        oSoapEnvelope.enc = SoapSerializationEnvelope.ENC;

        System.out.println("soap Object !!!!!!________"+oSoapObject.toString());
        System.out.println("soap envelope !!!!++++++"+oSoapEnvelope.toString());

        HttpTransport httpTransport = new HttpTransport(strServerUrl);
        httpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");   
        httpTransport.debug = true; 
        System.out.println("---------BEFORE TRY BLOCK....");
        try
        {
            httpTransport.call(strSoapAction, oSoapEnvelope);
            System.out.println("INSIDE TRY BLOCK.......");
            strRequestData = (oSoapEnvelope.getResponse()).toString()+"inside try........";         
        }
        catch (Exception e)
        {
            e.printStackTrace();
            strRequestData = e.toString()+"Exception!!!!!!!!!!!!!!!!!!!!!";
        }       
        System.out.println("Request Data======" + strRequestData);
//      System.out.println("request dump ========"+httpTransport.requestDump);

//      strRequestData = httpTransport.requestDump+"=======DUMP=======";
        System.out.println("====dump report is=============="+httpTransport.requestDump);

        return strRequestData;
    }
}

从我的主屏幕,我使用此方法调用将国家/地区代码传递给方法。

oTsoapRequest.fnSendRequest("http://www.webservicex.net/country.asmx","http://www.webserviceX.NET","http://www.webservicex.net/country.asmx/ GetCountryByCountryCode","GetCountryByCountryCode",m_oZipCodeEditField.getText());

请帮助我摆脱这个异常。

i am getting this output when trying to connect to webservice

org.xmlpull.v1.XmlPullParserException:
unexpected type (position:END_DOCUMENT
null@1:0 i[0.0] n
java.io.InputStreamReader@6cf4fb80)

package com.rim.SoapRequest;

import net.rim.device.api.io.parser.soap.SOAPBody;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransport;

public class TSOAPRequest
{   

    public String fnSendRequest(String strServerUrl,String strServiceNamespace,String strSoapAction,String strMethodName,String strLablelText)
    {
        System.out.println("inside method !!!!!!!!");

        String strRequestData = "";

        SoapObject oSoapObject = new SoapObject(strServiceNamespace, strMethodName);
        SoapSerializationEnvelope oSoapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//      oSoapObject.addProperty("GetCountryByCountryCode",strLablelText);
        oSoapObject.addProperty("CountryCode",strLablelText);
        oSoapEnvelope.bodyOut = oSoapObject;
        oSoapEnvelope.dotNet = true;
        oSoapEnvelope.encodingStyle = SoapSerializationEnvelope.XSD;
        oSoapEnvelope.enc = SoapSerializationEnvelope.ENC;

        System.out.println("soap Object !!!!!!________"+oSoapObject.toString());
        System.out.println("soap envelope !!!!++++++"+oSoapEnvelope.toString());

        HttpTransport httpTransport = new HttpTransport(strServerUrl);
        httpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");   
        httpTransport.debug = true; 
        System.out.println("---------BEFORE TRY BLOCK....");
        try
        {
            httpTransport.call(strSoapAction, oSoapEnvelope);
            System.out.println("INSIDE TRY BLOCK.......");
            strRequestData = (oSoapEnvelope.getResponse()).toString()+"inside try........";         
        }
        catch (Exception e)
        {
            e.printStackTrace();
            strRequestData = e.toString()+"Exception!!!!!!!!!!!!!!!!!!!!!";
        }       
        System.out.println("Request Data======" + strRequestData);
//      System.out.println("request dump ========"+httpTransport.requestDump);

//      strRequestData = httpTransport.requestDump+"=======DUMP=======";
        System.out.println("====dump report is=============="+httpTransport.requestDump);

        return strRequestData;
    }
}

from my main screen i am passing country code to the methos using this method call.

oTsoapRequest.fnSendRequest("http://www.webservicex.net/country.asmx","http://www.webserviceX.NET","http://www.webservicex.net/country.asmx/GetCountryByCountryCode","GetCountryByCountryCode",m_oZipCodeEditField.getText());

please help me in getting out of this exception.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文