2011-07-23 57 views
0

我試着去努力的Android網絡服務,但我已經邁出了仿真器輸出錯誤:的Android KSOAP輸出錯誤

org.xmlpull.v1.XmlPullParserException:expecteed:START_TAG {HTTP:/ /schemas.xmlsoap.org/soap/envelope/}Envelope(position:[email protected]:6在[email protected]

在這裏,我的代碼:

package com.webServiceDeneme; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.PropertyInfo; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.AndroidHttpTransport; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.*; 

public class WebServiceDenemeActivity extends Activity { 
Button btn; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    btn=(Button)findViewById(R.id.button1); 
    btn.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      String NAMESPACE="http://www.vakifbank.com.tr/"; 
      String METHOD_NAME="faiz-maliyet-oranlari.aspx"; 
      String SOAP_ACTION="http://www.vakifbank.com.tr/faiz-maliyet-oranlari.aspx"; 
      String URL="http://192.168.2.1/VipEvents/Services/BasicServices.asmx"; 
      SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME); 

      SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.dotNet=true; 
      envelope.setOutputSoapObject(request); 

      try 
      { 
       AndroidHttpTransport aht=new AndroidHttpTransport(URL); 
       aht.call(SOAP_ACTION, envelope); 
       SoapPrimitive res=(SoapPrimitive)envelope.getResponse(); 
       btn.setText(res.toString()); 

      } 
      catch (Exception e) { 
       // TODO: handle exception 
       btn.setText(e.toString()); 
       e.printStackTrace(); 
      } 
     } 
    }); 

}} 

任何幫助表示讚賞。

回答

0

您很可能收到了非SOAP響應。


轉儲和檢查SOAP請求/響應,設置aht.debug = true;,然後你叫aht.cal(...)後,打印值aht.requestDumpaht.responseDump輸出(如外部文件或logcat的)。

例如:

//... 
aht.debug = true; 
aht.call(SOAP_ACTION, envelope); 

Log.e("SOAP_REQUEST", "----------------------------"); 
Log.e("SOAP_REQUEST", XmlUtils.format(aht.requestDump)); 
Log.e("SOAP_REQUEST", "----------------------------"); 

Log.e("SOAP_RESPONSE", "----------------------------"); 
Log.e("SOAP_RESPONSE", XmlUtils.format(aht.responseDump)); 
Log.e("SOAP_RESPONSE", "----------------------------"); 

XmlUtils類有下面的代碼:

public class XmlUtils 
{ 
    static public String format(String unformattedXml) 
    { 
     StringWriter writer = new StringWriter(); 
     try 
     { 
      Document doc = parseXml(unformattedXml); 

      TransformerFactory tf = TransformerFactory.newInstance(); 
      Transformer transformer = tf.newTransformer(); 
      transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");   
      transformer.setOutputProperty(OutputKeys.METHOD, "xml"); 
      transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
      transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); 
      transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");     

      transformer.transform(new DOMSource(doc), new StreamResult(writer)); 
      writer.close(); 
     } 
     catch(Exception ex) 
     { 
      return unformattedXml; 
     } 


     return writer.toString(); 
    } 

    private static Document parseXml(String xml) throws IOException, ParserConfigurationException, SAXException 
    { 
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
     DocumentBuilder db = dbf.newDocumentBuilder(); 
     InputSource is = new InputSource(new StringReader(xml)); 
     return db.parse(is);   
    } 

} 
+0

我加你的代碼部分,但問題並沒有消失,有同樣的錯誤.. :( – rockenpeace

+0

這不應該解決你的問題,它應該幫助你驗證你收到的SOAP響應,即肥皂信封;而不是一些隨機響應 – inazaruk

+0

我看..我想我應該添加p ropertyinfo部分,因爲這個問題不是來自網站(「www.vakifbank.com.tr」可用)..非常感謝.. – rockenpeace