我正在尝试在Android上运行此http://www.apniurdu.com/Soap.html网络服务。
private static final String cMETHOD_NAME = "Translate";
private static final String cSOAP_ACTION = "http://apniurdu.com/SOAP/Urdu2.wsdl/Translate"";
private static final String cNAMESPACE = "http://apniurdu.com/SOAP/Urdu2.wsdl";
private static final String cURL = "http://apniurdu.com/SOAP/SOAP.pl";
public SoapObject Translatesoap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
java.lang.String symbol="hello world, good morning";
request.addProperty("symbol", symbol); //variable name, value. I got the variable name, from the wsdl file!
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
envelope.setOutputSoapObject(request); //prepare request
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent message was (httpTransport.requestDump)
httpTransport.call(SOAP_ACTION, envelope); //send request
SoapObject result=(SoapObject)envelope.getResponse(); //get response
return result;
}
try {
SoapObject result=Translatesoap(cMETHOD_NAME, cSOAP_ACTION, cNAMESPACE, cURL);
// Log.v("ergebnis", result.getProperty(1).toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.v("next", "try");
这基本上是我的代码。第一变量;第二个程序,第三个程序的调用。 运行时我得到一个XMLpullparser异常:
01-07 12:06:32.858: W/System.err(969): org.xmlpull.v1.XmlPullParserException: Expected a quoted string (position:DOCDECL @1:50 in java.io.InputStreamReader@412d9088)
01-07 12:06:32.858: W/System.err(969): at org.kxml2.io.KXmlParser.readQuotedId(KXmlParser.java:664)
01-07 12:06:32.868: W/System.err(969): at org.kxml2.io.KXmlParser.readExternalId(KXmlParser.java:643)
01-07 12:06:32.868: W/System.err(969): at org.kxml2.io.KXmlParser.readDoctype(KXmlParser.java:585)
01-07 12:06:32.868: W/System.err(969): at org.kxml2.io.KXmlParser.next(KXmlParser.java:418)
01-07 12:06:32.868: W/System.err(969): at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
01-07 12:06:32.868: W/System.err(969): at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2029)
01-07 12:06:32.878: W/System.err(969): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
01-07 12:06:32.878: W/System.err(969): at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
01-07 12:06:32.878: W/System.err(969): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
01-07 12:06:32.878: W/System.err(969): at com.example.c_f_converter_ksoap2.ManuelleSOAP.Translatesoap(ManuelleSOAP.java:64)
01-07 12:06:32.889: W/System.err(969): at com.example.c_f_converter_ksoap2.ManuelleSOAP$2.onClick(ManuelleSOAP.java:102)
01-07 12:06:32.889: W/System.err(969): at android.view.View.performClick(View.java:3511)
01-07 12:06:32.898: W/System.err(969): at android.view.View$PerformClick.run(View.java:14105)
01-07 12:06:32.898: W/System.err(969): at android.os.Handler.handleCallback(Handler.java:605)
01-07 12:06:32.898: W/System.err(969): at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 12:06:32.898: W/System.err(969): at android.os.Looper.loop(Looper.java:137)
01-07 12:06:32.908: W/System.err(969): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-07 12:06:32.908: W/System.err(969): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 12:06:32.918: W/System.err(969): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 12:06:32.927: W/System.err(969): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-07 12:06:32.927: W/System.err(969): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-07 12:06:32.927: W/System.err(969): at dalvik.system.NativeStart.main(Native Method)
01-07 12:06:32.927: V/next(969): try
简而言之:据我所知,预期在解析响应中引用一个字符串。 任何线索如何解决?非常感谢提前!
更新: 我想我使用了错误的URL ..现在我将URL更改为wsdl URL“http://apniurdu.com/SOAP/Urdu2.wsdl”并收到错误“意外启动令牌”
01-07 13:09:23.527: W/System.err(1149): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <definitions name='UrduSOAP' targetNamespace='http://apniurdu.com/SOAP/Urdu2.wsdl'>@10:43 in java.io.InputStreamReader@412dbf58)
wsdl与ksoap2不兼容吗?或者我做错了什么?感谢
答案 0 :(得分:0)
我认为你的问题是这一行
private static final String cSOAP_ACTION = "http://apniurdu.com/SOAP/Urdu2.wsdl/Translate"";
也许你必须删除&amp; quot,所以你应该这样写:
private static final String cSOAP_ACTION = "http://apniurdu.com/SOAP/Urdu2.wsdl/Translate";
修改强>
这不是问题所在,但对于OP来说,开始使用ksoap2有点帮助
public SoapObject testMethod(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL, String parameter) throws IOException, XmlPullParserException
{
List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("variablename", parameter);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//envelope.dotNet = true; for .net services
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.call(SOAP_ACTION, envelope, headers);
return (SoapObject) envelope.getResponse();
}
所以这是一个使用ksoap2和字符串参数的基本调用。