kSOAP2 输出 / org.xmlpull.v1.xmlpullparserexception 预期 start_tag

发布于 2024-10-06 14:38:52 字数 428 浏览 3 评论 0原文

我有一个标准代码来调用.net webservice

我在行中得到Exception“org.xmlpull.v1.xmlpullparserexception Expected start_tag”

transportSE.call(SOAP_ACTION,soapSerializationEnvelope);

但是,如果我从以下位置调用相同的Web服务.NET 代码 我根据需要得到了结构良好的正确输出。

主要看起来,从 kSOAP2 中,它得到了明确的输出,但是当它进一步解析 SoapPrimitive 对象时,它会失败。

那么,是否有其他方法可以查看收到的实际输出(实际肥皂信封),然后可以自己适当地解析它。

I have a standard code to call a .net webservice

I get exception "org.xmlpull.v1.xmlpullparserexception expected start_tag" at line

transportSE.call(SOAP_ACTION,soapSerializationEnvelope);

However, if i call the same webservice from a .NET code i get a well structured proper output as desired.

It primarily seems that from kSOAP2, there is a definite output that it gets but when it goes to parse further w.r.t SoapPrimitive objects, it fails.

So, is there other way to look at the actual output (actual soap envelope) received and then may be parse it myself appropriately.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

花之痕靓丽 2024-10-13 14:38:53

我正在调查我遇到的类似问题。无意中看到这条评论

当我使用 SoapEnvelope.VER11 时,它工作正常,但是当我使用
SoapEnvelope.VER12,它给我错误:
“org.xmlpull.v1.XmlPullParserException:预期:START_TAG”。

http://groups.google.com/group/android-developers/browse_thread /thread/b585862b6e939fd2

也许我们遇到了有关肥皂版本的兼容性问题。另外,连接到 .net 服务时,您可能需要设置 envelope.dotNet = true; ..但您可能已经这样做了

I'm investigating a similar problem I'm having. Stumbled across this comment

When I use SoapEnvelope.VER11, it works fine, But when I use
SoapEnvelope.VER12, it gives me error:
"org.xmlpull.v1.XmlPullParserException: expected: START_TAG".

http://groups.google.com/group/android-developers/browse_thread/thread/b585862b6e939fd2

Perhaps we are having compatibility issues regarding the soap version. Also connecting to a dot net service you may need to set envelope.dotNet = true; .. but you've probably done that

爱*していゐ 2024-10-13 14:38:53

我收到此 START_TAG 异常,但就我而言,这是因为我的值

METHOD_NAME="";
NAMESPACE ="";      
SOAP_ACTION ="";
URL ="";

不正确。

现在如何找出这些参数的正确值,您可以在此处查看我的其他答案

SoapObject req = new SoapObject(NAMESPACE,METHOD_NAME);
            //SoapObject req = new SoapObject(Namespace_Server,MethodName_Server);

    //req.addProperty("ImageData", Base64.encode(data));
    req.addProperty("ImageData", data);
    req.addProperty("login", CommonStaticData.getusername());
    req.addProperty("password",CommonStaticData.getpassword());
    req.addProperty("recipeId",FileID);

    MarshalBase64 mbase = new MarshalBase64();// marshal is used to serialize the byte array

    SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelop.bodyOut = req;
    envelop.encodingStyle = SoapSerializationEnvelope.ENC2001;
    envelop.dotNet = true;
    envelop.setOutputSoapObject(req);


    HttpTransportSE aht = new HttpTransportSE(URL);

    mbase.register(envelop);


    aht.call(SOAP_ACTION,envelop);

I was getting this START_TAG Exception but in my case it was because my values for

METHOD_NAME="";
NAMESPACE ="";      
SOAP_ACTION ="";
URL ="";

were not correct.

Now How to find out the correct values of these parameters you can Check out my other answer here

SoapObject req = new SoapObject(NAMESPACE,METHOD_NAME);
            //SoapObject req = new SoapObject(Namespace_Server,MethodName_Server);

    //req.addProperty("ImageData", Base64.encode(data));
    req.addProperty("ImageData", data);
    req.addProperty("login", CommonStaticData.getusername());
    req.addProperty("password",CommonStaticData.getpassword());
    req.addProperty("recipeId",FileID);

    MarshalBase64 mbase = new MarshalBase64();// marshal is used to serialize the byte array

    SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelop.bodyOut = req;
    envelop.encodingStyle = SoapSerializationEnvelope.ENC2001;
    envelop.dotNet = true;
    envelop.setOutputSoapObject(req);


    HttpTransportSE aht = new HttpTransportSE(URL);

    mbase.register(envelop);


    aht.call(SOAP_ACTION,envelop);
南城追梦 2024-10-13 14:38:53

现在我已经解决了我原来的问题,现在就来解决这个问题吧!

我发现 ksoap2 无法解析响应...特别是 org.kxml2.io.KXmlParser.require(type, namespace, name) 抛出以下异常。

WARN/System.err(2330): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <h1>@1:4 in java.io.InputStreamReader@47ff3050) 

请注意 h1 标签。这来自

404 Not Found

...所以是的,请注意您的回复可能来自网站,而不是您的网络服务:)

希望有一天能对某人有所帮助

Well now that I've solved my original problem hit this one!

I found that ksoap2 couldn't parse the response... specifically org.kxml2.io.KXmlParser.require(type, namespace, name) threw the following exception.

WARN/System.err(2330): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2001/12/soap-envelope}Envelope (position:START_TAG <h1>@1:4 in java.io.InputStreamReader@47ff3050) 

Note that h1 tag. That comes from <h1>404 Not Found</h1> ... so yes, be aware your response may be from a website but not your web service :)

Hope that helps someone one day

各空 2024-10-13 14:38:53

我遇到了几乎相同的错误,我的例外是“position:START_TAG @2:7”,

但我已经修复了,因为我以错误的方式命名了参数,该名称必须与 XSD 上指定的名称完全相同。

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
     request.addProperty("arg0_java_lang_String", "Club");

addPropery 方法中,我使用了错误的参数名称。

I had almost the same error, my exception was this "position:START_TAG @2:7"

but I've fixed because I was naming in a wrong way a parameter, the name must be exactly as is specified on the XSD.

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
     request.addProperty("arg0_java_lang_String", "Club");

in the addPropery method I was using a wrong parameter name.

豆芽 2024-10-13 14:38:53

使用下面的代码,通过观察变量 urlc.getResponseCode() 的响应代码来确保 Web 服务的 url 可访问,同时将IP从localhost、fixed、external最后更改为10.0.2.2

public static boolean isNetworkAvailable() {
//http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts/4009133#comment24565402_4009133
        /* ConnectivityManager cm =
                    (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo netInfo = cm.getActiveNetworkInfo();
                if (netInfo != null && netInfo.isConnected()) {//netInfo.isConnectedOrConnecting()
                    return true;
                }
                return false;*/

//http://stackoverflow.com/questions/5474089/how-to-check-currently-internet-connection-is-available-or-not-in-android?rq=1             
                boolean connected = false;
                ConnectivityManager connectivityManager = (ConnectivityManager)_context.getSystemService(Context.CONNECTIVITY_SERVICE);
                    if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || 
                            connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
                        //we are connected to a network
                        connected=true;
                        return connected;
                    }
                    else
                        {
                        connected=false;
                        return false;
                        }
    }

    public static boolean hasActiveInternetConnection() {
        if (isNetworkAvailable()) {
            try {
                //String url = "http://www.google.com",
                String url = "http://10.0.2.2:8089/UNIV_AXIS_DYN_WEB/services/ServiceMethods?wsdl",
                        proxy = "proxy.rss.jo",
                        port= "8080";
                URL server = new URL(url);
                Properties systemProperties = System.getProperties();
                /*systemProperties.setProperty("http.prosyHost",proxy);
                systemProperties.setProperty("http.prosyHost",port);*/
                HttpURLConnection urlc = (HttpURLConnection) (server.openConnection());
                urlc.setRequestProperty("User-Agent", "Test");
                urlc.setRequestProperty("Connection", "close");
                urlc.setConnectTimeout(500); 
                urlc.connect();
                System.out.println(urlc.getResponseCode());
                return (urlc.getResponseCode() == 200);
            } catch (IOException e) {
                Log.e(LOG_TAG, "Error checking internet connection", e);
                return false;
            }
        } else {
            Log.d(LOG_TAG, "No network available!");
            return false;
        }

    }

对我来说,我得到了这个提示“不是下面缺少的字符s

[错误] 尝试调用服务方法登录时发生异常
org.apache.axis2.AxisFault: 命名空间不匹配需要 http://services.univ.rss 找到 http://service.univ.rss

日志 tomcat 等的其余部分

at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:190)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

是的之后跟踪 LogCat 我没有检查 tomcat 服务器日志,如果 SoapUi 成功测试了该服务,您应该监控每次更改测试中的所有日志,我什至一开始忘记启动数据库服务,所以要小心:)

Soap Call

public SoapObject SoapCall(Vector<PropertyInfo> propertyInfo)

    {       

         Integer parametersSize = propertyInfo.size();

         //Initialize soap request + add parameters
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

         for(int i=0;i<parametersSize;i++)
         {
             request.addProperty(propertyInfo.get(i));
         }


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //envelope.dotNet = false; if service of type asmx .NET
        envelope.setOutputSoapObject(request);

        Log.d("App Log c ","c");

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            System.out.println(androidHttpTransport.getPort());
            // Make the soap call.
            //this is the actual part that will call the webservice
             androidHttpTransport.call(SOAP_ACTION, envelope);                      

             SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
             //Log.i("App Log 1 ", response.toString());

        } catch (Exception e) {
            e.printStackTrace(); 
        }

        // Get the SoapResult from the envelope body.       
        SoapObject result = (SoapObject)envelope.bodyIn;
        Log.i("App Log 2 ", result.toString());
        Log.i("App Log 2 ", result.getProperty(0).toString());

        return result;

    }

 Vector<PropertyInfo> vectorProperyInfo = new Vector<PropertyInfo>();

            PropertyInfo userProp = new PropertyInfo();
            userProp.setName("userName");
            userProp.setValue(username);
            userProp.setType(String.class);
            vectorProperyInfo.addElement(userProp);

            PropertyInfo passProp = new PropertyInfo();
            passProp.setName("pass");
            passProp.setValue(password);
            passProp.setType(String.class);
            vectorProperyInfo.addElement(passProp);

            SoapObject result = soapUtil.SoapCall(vectorProperyInfo);

           if (result != null && result.getProperty(0).toString().equals("1")) {
            return "LOGIN_SUCCESS";// for a student
        }

PS 我的数据库是 Oracle并且webservice是soap并使用 axis2-1.2 bin 并且在 Android 4.0 上测试,上述错误响应代码为 500 内部错误

After making sure the url of webservice is reachable by using the below code by watching variable urlc.getResponseCode() for response code while altering the ip from localhost ,fixed ,external and finally to 10.0.2.2

public static boolean isNetworkAvailable() {
//http://stackoverflow.com/questions/1560788/how-to-check-internet-access-on-android-inetaddress-never-timeouts/4009133#comment24565402_4009133
        /* ConnectivityManager cm =
                    (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo netInfo = cm.getActiveNetworkInfo();
                if (netInfo != null && netInfo.isConnected()) {//netInfo.isConnectedOrConnecting()
                    return true;
                }
                return false;*/

//http://stackoverflow.com/questions/5474089/how-to-check-currently-internet-connection-is-available-or-not-in-android?rq=1             
                boolean connected = false;
                ConnectivityManager connectivityManager = (ConnectivityManager)_context.getSystemService(Context.CONNECTIVITY_SERVICE);
                    if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED || 
                            connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
                        //we are connected to a network
                        connected=true;
                        return connected;
                    }
                    else
                        {
                        connected=false;
                        return false;
                        }
    }

    public static boolean hasActiveInternetConnection() {
        if (isNetworkAvailable()) {
            try {
                //String url = "http://www.google.com",
                String url = "http://10.0.2.2:8089/UNIV_AXIS_DYN_WEB/services/ServiceMethods?wsdl",
                        proxy = "proxy.rss.jo",
                        port= "8080";
                URL server = new URL(url);
                Properties systemProperties = System.getProperties();
                /*systemProperties.setProperty("http.prosyHost",proxy);
                systemProperties.setProperty("http.prosyHost",port);*/
                HttpURLConnection urlc = (HttpURLConnection) (server.openConnection());
                urlc.setRequestProperty("User-Agent", "Test");
                urlc.setRequestProperty("Connection", "close");
                urlc.setConnectTimeout(500); 
                urlc.connect();
                System.out.println(urlc.getResponseCode());
                return (urlc.getResponseCode() == 200);
            } catch (IOException e) {
                Log.e(LOG_TAG, "Error checking internet connection", e);
                return false;
            }
        } else {
            Log.d(LOG_TAG, "No network available!");
            return false;
        }

    }

For me i got this hint "not the missing character s in the below"

[ERROR] Exception occurred while trying to invoke service method login
org.apache.axis2.AxisFault: namespace mismatch require http://services.univ.rss found http://service.univ.rss

The rest of log tomcat etc

at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:190)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

And yes after tracing the LogCat i did not check th tomcat server log eve if the service was tested by SoapUi successfully , you should monitor all logs in every change test , i even forgot at first to start the database service so be carefull :)

The Soap Call

public SoapObject SoapCall(Vector<PropertyInfo> propertyInfo)

    {       

         Integer parametersSize = propertyInfo.size();

         //Initialize soap request + add parameters
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

         for(int i=0;i<parametersSize;i++)
         {
             request.addProperty(propertyInfo.get(i));
         }


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        //envelope.dotNet = false; if service of type asmx .NET
        envelope.setOutputSoapObject(request);

        Log.d("App Log c ","c");

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        try {
            System.out.println(androidHttpTransport.getPort());
            // Make the soap call.
            //this is the actual part that will call the webservice
             androidHttpTransport.call(SOAP_ACTION, envelope);                      

             SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
             //Log.i("App Log 1 ", response.toString());

        } catch (Exception e) {
            e.printStackTrace(); 
        }

        // Get the SoapResult from the envelope body.       
        SoapObject result = (SoapObject)envelope.bodyIn;
        Log.i("App Log 2 ", result.toString());
        Log.i("App Log 2 ", result.getProperty(0).toString());

        return result;

    }

 Vector<PropertyInfo> vectorProperyInfo = new Vector<PropertyInfo>();

            PropertyInfo userProp = new PropertyInfo();
            userProp.setName("userName");
            userProp.setValue(username);
            userProp.setType(String.class);
            vectorProperyInfo.addElement(userProp);

            PropertyInfo passProp = new PropertyInfo();
            passProp.setName("pass");
            passProp.setValue(password);
            passProp.setType(String.class);
            vectorProperyInfo.addElement(passProp);

            SoapObject result = soapUtil.SoapCall(vectorProperyInfo);

           if (result != null && result.getProperty(0).toString().equals("1")) {
            return "LOGIN_SUCCESS";// for a student
        }

P.S My Db Is Oracle and webservice is soap and used axis2-1.2 bin And tested on Android 4.0 the above error response code was 500 Internal Error

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文