我有一个标准代码来调用.net webservice
我在{<1}}行
exception "org.xmlpull.v1.xmlpullparserexception expected start_tag"
但是,如果我从transportSE.call(SOAP_ACTION,soapSerializationEnvelope);
调用相同的Web服务,我会根据需要获得结构合理的正确输出。
主要看来,从.NET code
开始,它有一个明确的输出,但是当它进一步解析w.r.t SoapPrimitive对象时,它会失败。
那么,是否有其他方法可以查看收到的实际输出(实际肥皂信封),然后可以自己解析它。
答案 0 :(得分:2)
我正在调查我遇到的类似问题。偶然发现了这条评论
当我使用SoapEnvelope.VER11时,它工作正常,但是当我使用时 SoapEnvelope.VER12,它给了我错误: “org.xmlpull.v1.XmlPullParserException:expected:START_TAG”。
http://groups.google.com/group/android-developers/browse_thread/thread/b585862b6e939fd2
也许我们遇到有关soap版本的兼容性问题。同样连接到dot net服务,您可能需要设置envelope.dotNet = true;
..但您可能已经完成了
答案 1 :(得分:2)
我收到了这个START_TAG例外,但就我而言,这是因为我的
值METHOD_NAME="";
NAMESPACE ="";
SOAP_ACTION ="";
URL ="";
不正确。
现在如何查找这些参数的正确值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);
答案 2 :(得分:1)
现在好了,我已经解决了我的原始问题!
我发现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标签。这来自<h1>404 Not Found</h1>
...是的,请注意您的回复可能来自网站但不是您的网络服务:)
希望有一天可以帮助某人
答案 3 :(得分:0)
我有几乎相同的错误,我的例外是这个“位置:START_TAG @ 2:7”
但我已修复,因为我以错误的方式命名参数,名称必须与XSD上指定的完全相同。
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("arg0_java_lang_String", "Club");
在 addPropery 方法中,我使用了错误的参数名称。
答案 4 :(得分:0)
通过使用以下代码确保网络服务的网址可访问后,通过观察变量 urlc.getResponseCode()
获取响应代码,同时从更改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 ”
<强> [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
强>
其余的log 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成功测试了服务,你应该监控每个变更测试中的所有日志,我甚至忘了一开始就启动数据库服务所以要小心:))
肥皂电话
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 我的Db是Oracle和webservice是肥皂并使用axis2-1.2 bin并在Android 4.0上测试了以上错误响应代码为500 Internal Error