2012-02-07 24 views
1

我學習了很多並試圖解決它,但我面臨的問題是在屏幕上顯示響應。在Android中顯示肥皂響應(陣列)

SOAP服務代碼是::

POST /ws1.asmx HTTP/1.1 
Host: www.xyz.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://xyx.com/webservices/LoadServices" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <LoadServices xmlns="http://xyz.com/webservices/" /> 
    </soap:Body> 
</soap:Envelope> 
HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <LoadServicesResponse xmlns="http://xyz.com/webservices/"> 
     <LoadServicesResult> 
     <anyType /> 
     <anyType /> 
     </LoadServicesResult> 
    </LoadServicesResponse> 
    </soap:Body> 
</soap:Envelope> 

我正在使用的Java 2類。這裏是它的代碼。

首先我加入Category.java代碼:

import java.util.Hashtable; 
import org.ksoap2.serialization.KvmSerializable; 
import org.ksoap2.serialization.PropertyInfo; 

import android.util.Log; 

public class Category implements KvmSerializable 
{ 
    public int CompanyId;    //0 
    public int ServiceId;    //1 
    public String ServiceMessage;  //2 
    public int ServiceCategoryId;  //3 
    public boolean IsVisibleForUser; //4 
    public String ServiceName;   //5 
    public String Serviceform;   //6 
    public char IsActive;    //7 
    public String ServiceImage;   //8 
    public String ServiceCode;   //9 
    public String RequestFulfilledMsg; //10 
    public String ToDoPendingRequest; //11 
    public String CompanyName;   //12 
    public String ServiceCategoryName; //13 
    public String ThumbnailImage;  //14  
    public String ServiceDescription; //15 





    public Category() 
    {} 

    public Category(int coid, int servId, int scid) 
    { 
     CompanyId = coid; 
     ServiceId = servId; 
     ServiceCategoryId = scid; 

    } 


    public Object getProperty(int arg0) 
    { 
     Log.i("Category", "msg:getProperty"); 
     switch(arg0) 
     { 
     case 0: 
      return CompanyId; 

     case 1: 
      return ServiceId; 

     case 3: 
      return ServiceCategoryId; 

     } 

     return null; 
    } 




    public int getPropertyCount() 
    { 
     Log.i("Category", "msg:getPropertyCount(3)"); 
     return 3; 
    } 

    public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) 
    { 
     Log.i("Category", "msg:getPropertyInfo"); 
     switch (index) 
     { 
     case 0: 
      info.type = PropertyInfo.INTEGER_CLASS; 
      info.name = "CompanyId"; 
      break; 

     case 1: 
      info.type = PropertyInfo.INTEGER_CLASS; 
      info.name = "ServiceId"; 
      break; 

     case 3: 
      info.type = PropertyInfo.INTEGER_CLASS; 
      info.name = "ServiceCategoryId"; 
      break; 


      default: 
       break; 
     } 

    } 


    public void setProperty(int index, Object value) 
    { 
     Log.i("Category", "msg:SetProperty"); 
     switch (index) 
     { 

     case 0: 
      CompanyId = Integer.parseInt(value.toString()); 
      break; 

     case 1: 
      ServiceId = Integer.parseInt(value.toString()); 
      break; 

     case 3: 
      ServiceCategoryId = Integer.parseInt(value.toString()); 
      break; 


     default: 
      break; 
     } 

    } 

} 

現在根系活力的代碼,即WebServiceEx.java

public class WebServiceEx extends Activity 
{ 
    private final String NAMESPACE = "http://xyz.com/webservices/"; 
    private final String URL = "http://www.abc.com/ws1.asmx"; 
    private final String SOAP_ACTION = "http://xyz.com/webservices/LoadServices"; 
    private final String METHOD_NAME = "LoadServices"; 

    //public Array array = null; 
    //String arr[] = null; 

    TextView tv; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     tv = new TextView(this); 

     LoadSoapService(); 
     setContentView(tv); 
    } 


    private void LoadSoapService() 
    { 
     Log.i("WebService", "msg:soap enter"); 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


     Category C = new Category(); 
     C.ServiceCategoryId = 1; 
     Log.i("WebService", "msg:Category"); 

     Log.i("WebService", "msg:Property"); 

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

     Log.i("WebService", "msg:Request"); 

     envelope.addMapping(NAMESPACE, "Category", new Category().getClass()); 

     HttpTransportSE transportSE = new HttpTransportSE(URL); 

     Log.i("WebService", "msg:try_out"); 
     try 
     { 
           Log.i("WebService", "msg:try+in"); 
      transportSE.call(SOAP_ACTION, envelope);        
           Log.i("WebService", "msg:SoapObject"); 
      SoapObject response = (SoapObject)envelope.getResponse();    /**error here, wents to exception **/ 

           Log.i("WebService", "Response"); 

           Log.i("WebSrv", response.toString()); 


      C.ServiceCategoryId = Integer.parseInt(response.getProperty(3).toString()); 

      tv.setText(" "+C.ServiceCategoryId); 


     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
      Log.i("WebService", "msg:Exception error"); 
     } 

    } 
} 

我不得不添加從發生問題的評論,不管如果我失去了什麼,告訴我,因爲一切都在你的面前。

我已將ksoap2添加到外部Jar並添加了Internet權限,所有我遇到的問題都是空白屏幕。

希望能得到一些想法,

感謝, Harpreet。

回答

3

如果我是你,我會做

private void LoadSoapService() 

這梅託德如下:

private String LoadSoapService() 

返回Integer.parseInt(response.getProperty(3).toString()); 並設置TextViews文字

tv.setText(LoadSoapService); 
+0

您好,感謝您回覆。 – Harpreet 2012-02-07 13:40:46

+0

我也會嘗試這樣做,但是現在我只是測試單個元素,實際上我必須使用所有這16個元素。這16個元素將在每個數組的索引處出現。 – Harpreet 2012-02-07 13:43:34

+0

但兄弟。現在嘗試塊沒有執行到這個程度,我已經在Java代碼中添加註釋,直到TRY塊執行的地方程序。它的舉動抓住阻滯。我應該在這裏添加StackTrace它返回? – Harpreet 2012-02-07 13:53:52