XML Pull Parser异常 - kSOAP2(XML Pull Parser Exception - kSOAP2)
尝试使用
kSOAP2
从Android
访问Web服务时,我收到了XmlPullParserException
。以下是我的代码:
NAMESPACE = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices?wsdl"; URL = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices"; SOAP_ACTION = "EmployeeServicesPortBinding"; METHOD_NAME = "authorize"; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("employeeId", userID); request.addProperty("localeId", localeID); request.addProperty("organizationId", organisationID); request.addProperty("retailLocationId", retailLoationID); request.addProperty("workstationId", workstationID); request.addProperty("LoginInput", userID); request.addProperty("Password", password); request.addProperty("LoginInputType", loginInputType); request.addProperty("Privilege", privilege); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); Object obj = envelope.bodyIn; SoapObject response = null; if (obj instanceof SoapObject) response = (SoapObject) (envelope.bodyIn); responseCode = (response != null) ? response.getProperty("UserAuthorizeResponse").toString() : "Failed"; Toast.makeText(getApplicationContext(), responseCode, Toast.LENGTH_SHORT).show(); //Testing } catch (Exception e) { Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT).show(); //Testing System.out.println(""); }
WSDL:
<?xml version="1.0" encoding="UTF-8" ?> - <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-. --> - <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-. --> - <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.xx.com/xservices/EmployeeServices" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.xx.com/xservices/EmployeeServices" name="EmployeeServices"> - <types> - <xsd:schema> <xsd:import namespace="http://ws.xx.com/xservices/EmployeeServices" schemaLocation="http://10.99.60.52:8080/ws/EmployeeServices?xsd=1" /> </xsd:schema> </types> - <message name="changePassword"> <part name="parameters" element="tns:changePassword" /> </message> - <message name="changePasswordResponse"> <part name="parameters" element="tns:changePasswordResponse" /> </message> - <message name="getCommissionedAssociates"> <part name="parameters" element="tns:getCommissionedAssociates" /> </message> - <message name="getCommissionedAssociatesResponse"> <part name="parameters" element="tns:getCommissionedAssociatesResponse" /> </message> - <message name="authorize"> <part name="parameters" element="tns:authorize" /> </message> - <message name="authorizeResponse"> <part name="parameters" element="tns:authorizeResponse" /> </message> - <message name="deleteMessage"> <part name="parameters" element="tns:deleteMessage" /> </message> - <message name="deleteMessageResponse"> <part name="parameters" element="tns:deleteMessageResponse" /> </message> - <message name="updateMessage"> <part name="parameters" element="tns:updateMessage" /> </message> - <message name="updateMessageResponse"> <part name="parameters" element="tns:updateMessageResponse" /> </message> - <message name="addMessage"> <part name="parameters" element="tns:addMessage" /> </message> - <message name="addMessageResponse"> <part name="parameters" element="tns:addMessageResponse" /> </message> - <message name="validateEmp"> <part name="parameters" element="tns:validateEmp" /> </message> - <message name="validateEmpResponse"> <part name="parameters" element="tns:validateEmpResponse" /> </message> - <message name="authenticate"> <part name="parameters" element="tns:authenticate" /> </message> - <message name="authenticateResponse"> <part name="parameters" element="tns:authenticateResponse" /> </message> - <portType name="EmployeeServices"> - <operation name="changePassword"> <input message="tns:changePassword" /> <output message="tns:changePasswordResponse" /> </operation> - <operation name="getCommissionedAssociates"> <input message="tns:getCommissionedAssociates" /> <output message="tns:getCommissionedAssociatesResponse" /> </operation> - <operation name="authorize"> <input message="tns:authorize" /> <output message="tns:authorizeResponse" /> </operation> - <operation name="deleteMessage"> <input message="tns:deleteMessage" /> <output message="tns:deleteMessageResponse" /> </operation> - <operation name="updateMessage"> <input message="tns:updateMessage" /> <output message="tns:updateMessageResponse" /> </operation> - <operation name="addMessage"> <input message="tns:addMessage" /> <output message="tns:addMessageResponse" /> </operation> - <operation name="validateEmp"> <input message="tns:validateEmp" /> <output message="tns:validateEmpResponse" /> </operation> - <operation name="authenticate"> <input message="tns:authenticate" /> <output message="tns:authenticateResponse" /> </operation> </portType> - <binding name="EmployeeServicesPortBinding" type="tns:EmployeeServices"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> - <operation name="changePassword"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="getCommissionedAssociates"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="authorize"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="deleteMessage"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="updateMessage"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="addMessage"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="validateEmp"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="authenticate"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> </binding> - <service name="EmployeeServices"> - <port name="EmployeeServicesPort" binding="tns:EmployeeServicesPortBinding"> <soap:address location="http://10.99.60.52:8080/ws/EmployeeServices" /> </port> </service> </definitions>
以下是我从SOAP UI发送的SOAP请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:emp="http://ws.xx.com/xservices/EmployeeServices"> <soapenv:Header/> <soapenv:Body> <emp:authorize> <!--Optional:--> <emp:ServiceContext> <!--Optional:--> <employeeId>8511</employeeId> <!--Optional:--> <localeId>en_US</localeId> <!--Optional:--> <organizationId>1</organizationId> <!--Optional:--> <retailLocationId>900</retailLocationId> <!--Optional:--> <workstationId>1</workstationId> </emp:ServiceContext> <!--Zero or more repetitions:--> <LoginInput>8511</LoginInput> <!--Optional:--> <Password>1</Password> <!--Optional:--> <LoginInputType>KEYBOARD</LoginInputType> <!--Optional:--> <Privilege>SELL_ITEM</Privilege> </emp:authorize> </soapenv:Body> </soapenv:Envelope>
这是我的SOAP响应,来自SOAP UI:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:authorizeResponse xmlns:ns2="http://ws.xx.com/xservices/EmployeeServices"> <UserAuthorizeResponse> <userAuthorized>true</userAuthorized> </UserAuthorizeResponse> </ns2:authorizeResponse> </S:Body> </S:Envelope>
这一行抛出异常:
androidHttpTransport.call(SOAP_ACTION, envelope);
更新错误:
expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:314 in java.io.InputStreamReader@40ec86e0) org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:313 in java.io.InputStreamReader@3e89c3) at org.kxml2.io.KXmlParser.exception(Unknown Source) at org.kxml2.io.KXmlParser.require(Unknown Source) at org.ksoap2.SoapEnvelope.parse(Unknown Source) at org.ksoap2.transport.Transport.parseResponse(Unknown Source) at org.ksoap2.transport.HttpTransportSE.call(Unknown Source) at SOAPClass.main(SOAPClass.java:55)
谁能澄清我做错了什么?
I'm getting
XmlPullParserException
when trying to hit the web service fromAndroid
, usingkSOAP2
.Below is my code:
NAMESPACE = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices?wsdl"; URL = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices"; SOAP_ACTION = "EmployeeServicesPortBinding"; METHOD_NAME = "authorize"; SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("employeeId", userID); request.addProperty("localeId", localeID); request.addProperty("organizationId", organisationID); request.addProperty("retailLocationId", retailLoationID); request.addProperty("workstationId", workstationID); request.addProperty("LoginInput", userID); request.addProperty("Password", password); request.addProperty("LoginInputType", loginInputType); request.addProperty("Privilege", privilege); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); Object obj = envelope.bodyIn; SoapObject response = null; if (obj instanceof SoapObject) response = (SoapObject) (envelope.bodyIn); responseCode = (response != null) ? response.getProperty("UserAuthorizeResponse").toString() : "Failed"; Toast.makeText(getApplicationContext(), responseCode, Toast.LENGTH_SHORT).show(); //Testing } catch (Exception e) { Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT).show(); //Testing System.out.println(""); }
WSDL:
<?xml version="1.0" encoding="UTF-8" ?> - <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-. --> - <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-. --> - <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.xx.com/xservices/EmployeeServices" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.xx.com/xservices/EmployeeServices" name="EmployeeServices"> - <types> - <xsd:schema> <xsd:import namespace="http://ws.xx.com/xservices/EmployeeServices" schemaLocation="http://10.99.60.52:8080/ws/EmployeeServices?xsd=1" /> </xsd:schema> </types> - <message name="changePassword"> <part name="parameters" element="tns:changePassword" /> </message> - <message name="changePasswordResponse"> <part name="parameters" element="tns:changePasswordResponse" /> </message> - <message name="getCommissionedAssociates"> <part name="parameters" element="tns:getCommissionedAssociates" /> </message> - <message name="getCommissionedAssociatesResponse"> <part name="parameters" element="tns:getCommissionedAssociatesResponse" /> </message> - <message name="authorize"> <part name="parameters" element="tns:authorize" /> </message> - <message name="authorizeResponse"> <part name="parameters" element="tns:authorizeResponse" /> </message> - <message name="deleteMessage"> <part name="parameters" element="tns:deleteMessage" /> </message> - <message name="deleteMessageResponse"> <part name="parameters" element="tns:deleteMessageResponse" /> </message> - <message name="updateMessage"> <part name="parameters" element="tns:updateMessage" /> </message> - <message name="updateMessageResponse"> <part name="parameters" element="tns:updateMessageResponse" /> </message> - <message name="addMessage"> <part name="parameters" element="tns:addMessage" /> </message> - <message name="addMessageResponse"> <part name="parameters" element="tns:addMessageResponse" /> </message> - <message name="validateEmp"> <part name="parameters" element="tns:validateEmp" /> </message> - <message name="validateEmpResponse"> <part name="parameters" element="tns:validateEmpResponse" /> </message> - <message name="authenticate"> <part name="parameters" element="tns:authenticate" /> </message> - <message name="authenticateResponse"> <part name="parameters" element="tns:authenticateResponse" /> </message> - <portType name="EmployeeServices"> - <operation name="changePassword"> <input message="tns:changePassword" /> <output message="tns:changePasswordResponse" /> </operation> - <operation name="getCommissionedAssociates"> <input message="tns:getCommissionedAssociates" /> <output message="tns:getCommissionedAssociatesResponse" /> </operation> - <operation name="authorize"> <input message="tns:authorize" /> <output message="tns:authorizeResponse" /> </operation> - <operation name="deleteMessage"> <input message="tns:deleteMessage" /> <output message="tns:deleteMessageResponse" /> </operation> - <operation name="updateMessage"> <input message="tns:updateMessage" /> <output message="tns:updateMessageResponse" /> </operation> - <operation name="addMessage"> <input message="tns:addMessage" /> <output message="tns:addMessageResponse" /> </operation> - <operation name="validateEmp"> <input message="tns:validateEmp" /> <output message="tns:validateEmpResponse" /> </operation> - <operation name="authenticate"> <input message="tns:authenticate" /> <output message="tns:authenticateResponse" /> </operation> </portType> - <binding name="EmployeeServicesPortBinding" type="tns:EmployeeServices"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> - <operation name="changePassword"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="getCommissionedAssociates"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="authorize"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="deleteMessage"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="updateMessage"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="addMessage"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="validateEmp"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> - <operation name="authenticate"> <soap:operation soapAction="" /> - <input> <soap:body use="literal" /> </input> - <output> <soap:body use="literal" /> </output> </operation> </binding> - <service name="EmployeeServices"> - <port name="EmployeeServicesPort" binding="tns:EmployeeServicesPortBinding"> <soap:address location="http://10.99.60.52:8080/ws/EmployeeServices" /> </port> </service> </definitions>
Below is my SOAP request, sent from SOAP UI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:emp="http://ws.xx.com/xservices/EmployeeServices"> <soapenv:Header/> <soapenv:Body> <emp:authorize> <!--Optional:--> <emp:ServiceContext> <!--Optional:--> <employeeId>8511</employeeId> <!--Optional:--> <localeId>en_US</localeId> <!--Optional:--> <organizationId>1</organizationId> <!--Optional:--> <retailLocationId>900</retailLocationId> <!--Optional:--> <workstationId>1</workstationId> </emp:ServiceContext> <!--Zero or more repetitions:--> <LoginInput>8511</LoginInput> <!--Optional:--> <Password>1</Password> <!--Optional:--> <LoginInputType>KEYBOARD</LoginInputType> <!--Optional:--> <Privilege>SELL_ITEM</Privilege> </emp:authorize> </soapenv:Body> </soapenv:Envelope>
Here is my SOAP response, got from SOAP UI:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:authorizeResponse xmlns:ns2="http://ws.xx.com/xservices/EmployeeServices"> <UserAuthorizeResponse> <userAuthorized>true</userAuthorized> </UserAuthorizeResponse> </ns2:authorizeResponse> </S:Body> </S:Envelope>
This line is throwing below exception:
androidHttpTransport.call(SOAP_ACTION, envelope);
Updated Error:
expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:314 in java.io.InputStreamReader@40ec86e0) org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:313 in java.io.InputStreamReader@3e89c3) at org.kxml2.io.KXmlParser.exception(Unknown Source) at org.kxml2.io.KXmlParser.require(Unknown Source) at org.ksoap2.SoapEnvelope.parse(Unknown Source) at org.ksoap2.transport.Transport.parseResponse(Unknown Source) at org.ksoap2.transport.HttpTransportSE.call(Unknown Source) at SOAPClass.main(SOAPClass.java:55)
Can anyone clarify what I'm doing wrong?
原文:https://stackoverflow.com/questions/20966426
最满意答案
要直接回答你的问题,
您必须意识到新的
<!DOCTYPE HTML>
doctype仅用于在浏览器中触发标准兼容模式。 传统上,从浏览器的角度来看,这个(称为doctype切换)是doctype用于唯一的东西。 因此,简而言之,如果您使用的是已触发标准模式的doctype,则IE6不会发生任何变化。您可以使用Modernizr之类的脚本进行特征检测。 这将允许您仅在需要时使用Flash作为后备,并向支持它们的浏览器提供正确类型的电影。 即使您不使用该脚本,您仍然可以查看其来源以了解如何完成此操作。
或者,
<video>
和<audio>
标签专门允许将后备内容嵌入其中。 这意味着您只需使用<video>
标记包装Flash内容,如果浏览器不支持它们,则只需使用后备内容即可。To answer your question directly,
You have to realize that the new
<!DOCTYPE HTML>
doctype is only used to trigger standard compliant mode in browsers. Traditionally, this (known as doctype switching) is the only thing the doctype is used for from the browser's perspective. So in short, nothing will happen change with respect to IE6 if you are using a doctype that already trigger standard mode.You can use a script like Modernizr to do feature detection. This will allow you to use Flash as a fallback only in cases when its needed, as well as serve up the correct type of movie to browsers that support them. Even if you do not use the script, you can still look at its source to learn how this is done.
Alternatively, the
<video>
and<audio>
tag specifically allow for fallback content to be embedded within them. This will means that you can simply wrap your Flash content with<video>
tags, and if the browser does not support them it will simply use the fallback content.
相关问答
更多-
是的,浏览器只会忽略未知属性。 Yes, browsers will just ignore unknown attributes.
-
您可以查看HTML5样板文件 。 如果你看一下index.html第一行,你会看到如何根据浏览器使用CSS的各种功能, 所有这些功能都在同一个CSS文件中 。 这个想法最初是在这里解释的。 很简单,诀窍是根据浏览器有条件地定义哪些CSS类适用于body 。 You could have a look at HTML5 boilerplate. If you take a look at the very first lines of index.html, you'll see how to use var ...
-
移动浏览器支持CSS3(CSS3 support in mobile browsers)[2022-03-08]
iPhone和Android系统都使用WebKit作为移动浏览器中的渲染引擎。 我相信黑莓也会转向Webkit。 这款引擎目前提供了部分CSS 3的部分最佳支持,以及相当多的专有扩展。 我会推荐研究WebKit中可用的内容,然后进行测试。 支持表的一个很好的资源是http: //www.quirksmode.org,PPK正在做越来越多的移动浏览器测试来回答这些问题。 Both iPhone and Android systems use WebKit as the rendering engine in ... -
好吧,好像我有不好的媒体功能包没有安装任何东西: http : //answers.microsoft.com/en-us/windows/forum/windows_10-other_settings/windows-10-n-media-feature-pack-not -工作-后/ 953d600b-BADD-4fdb-8756-6eb3b740d02e 从https://support.microsoft.com/en-us/kb/3099229安装后,它可以正常工作。 需要小心,因为我认为谷歌最好 ...
-
有很多JS库可以模糊图像。 BlurJS VagueJS StackBlur Algorhythm 无论如何,如果你使用的是静态模糊图像(也就是说,不需要再次渲染/模糊它),我会说你应该使用正常的位图图像。 这可能有助于避免浏览器上不必要的CPU负载和兼容性问题。 There are plenty of JS libraries that blur images. BlurJS VagueJS StackBlur Algorhythm Anyway, if you're using a static blu ...
-
如何在不支持html5的浏览器中显示输入类型=“日期”(How is input type=“date” displayed in browsers which do not support html5)[2023-01-04]
与HTML5 ,每个其他新引入的输入类型,如下: 请参阅HTML5 - input = number和不兼容的浏览器接受的答案。 As every other newly introduced input types by HTML5, as an: See HTML5 - input=number and incompatible browsers accepted answer. -
您可以使用HTML5 Boilerplate完成此操作。 它配备了Modernizr(包括html5shiv),还有更多。 html5boilerplate.com You can do this by using HTML5 Boilerplate. It comes with Modernizr (which includes html5shiv), and a lot more as well. html5boilerplate.com
-
要直接回答你的问题, 您必须意识到新的 doctype仅用于在浏览器中触发标准兼容模式。 传统上,从浏览器的角度来看,这个(称为doctype切换)是doctype用于唯一的东西。 因此,简而言之,如果您使用的是已触发标准模式的doctype,则IE6不会发生任何变化。 您可以使用Modernizr之类的脚本进行特征检测。 这将允许您仅在需要时使用Flash作为后备,并向支持它们的浏览器提供正确类型的电影。 即使您不使用该脚本,您仍然可以查看其来源以了解如何完成此操作。 或者, ...
-
我最近在IE中遇到了一个相当优雅的CSS3新解决方案。 我认为它非常接近你想要的东西: http : //css3pie.com/ I recently came across a rather elegant new solution for CSS3 in IE. I think it's pretty close to what you want: http://css3pie.com/
-
CSS3背景的最佳实践和对旧版浏览器的支持?(Best practice for CSS3 backgrounds and support for older browsers?)[2023-08-12]
关于CSS3 multiple backgounds和/或background gradients我认为有一种方法比你提出的方法更好: CSS3 Pie 。 通过这种方式,您可以在IE6,7和8中使用所有这些不错的效果(包括也可以使用border-radious ) 而无需任何JavaScript干预 。 About the CSS3 multiple backgounds and/or background gradients I think there is an approach better tha ...