2013-01-07 51 views
1

我試圖讓Android上運行此http://www.apniurdu.com/Soap.html Web服務。SOAP的Android pullparser例外預期引用字符串

private static final String cMETHOD_NAME = "Translate"; 
private static final String cSOAP_ACTION = "http://apniurdu.com/SOAP/Urdu2.wsdl/Translate&quot"; 
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 [email protected]) 
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 [email protected]) 

so wsdl與ksoap2不兼容?或者我做錯了什麼?感謝

回答

0

我覺得你的問題是此行

private static final String cSOAP_ACTION = "http://apniurdu.com/SOAP/Urdu2.wsdl/Translate&quot"; 

也許你需要刪除& QUOT,所以你應該這樣寫:

private static final String cSOAP_ACTION = "http://apniurdu.com/SOAP/Urdu2.wsdl/Translate"; 

編輯

這不是對於問題,但對於OP,有點幫助,開始使用kso​​ap2

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(); 
    } 

所以這是一個使用kso​​ap2和字符串參數的基本調用。

+0

這個沒有工作,我加入了與報價後,忘了將其刪除 - 然而,現在我得到另一個錯誤,請參閱更新後請 – user1497119

+0

我看着WSDL,也許我有一個想法。使用'private static final String cSOAP_ACTION =「http://apniurdu.com/SOAP/Urdu2.wsdl#Translate」;'。我將'/'字符改爲'#'。請試試這個。 –

+0

嗨,我也嘗試過,但沒有成功。現在,我在另一個計算器後讀的URL「不應該指向WSDL,但到PHP文件」,所以我現在真的不知道,如果「AndroidHttpTransport httpTransport =新AndroidHttpTransport(URL);」 URL應指向WSDL或在「肥皂:地址位置=」 http://apniurdu.com/SOAP/SOAP.pl」「服務位置 – user1497119