2012-01-16 164 views
0

爲什麼我無法從Web服務獲取結果?當我調試代碼時,它顯示一個異常。無法從Web服務檢索結果

以下代碼用於Web服務請求。

@SuppressWarnings("deprecation") 
protected boolean UserNameAvailability(final String sUserName) 
{ 
    boolean result = false; 

    SoapObject request = new SoapObject(getResources().getString(R.string.targetnamespace), getResources().getString(R.string.usernameavailabilitymethod)); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 

    PropertyInfo piUserName = new PropertyInfo(); 
    piUserName.name = "UserName"; 

    request.addProperty(piUserName, sUserName); 

    HttpTransportSE httpTransport = new HttpTransportSE(getResources().getString(R.string.webserviceurl));     
     try { 
      httpTransport.debug =true; 
      httpTransport.call(getResources().getString(R.string.usernameavailabilitysoapaction), envelope);      
      SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
      if (!response.toString().equals("false")) { 
       result = true; 

      } 
      //else 
      //{ 
      // alertBox("User Name already exists.Please enter different username."); 
      // } 

      }catch (Exception exception) { 
       Log.w("UserNameAvailability - RegisterActivity", "Error message is "+exception.getMessage(), exception); 
      } 


      return result; 
} 

登錄貓細節

01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at android.os.Looper.loop(Looper.java:123) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at java.lang.reflect.Method.invoke(Method.java:521) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
01-16 18:02:01.956: W/UserNameAvailability - RegisterActivity(241):  at dalvik.system.NativeStart.main(Native Method) 
01-16 18:13:43.946: I/ActivityManager(51): Displayed activity com.anb.eCalculator/.LoginActivity: 1988 ms (total 1988 ms) 
01-16 18:13:45.996: I/ActivityManager(51): Starting activity: Intent { cmp=com.anb.eCalculator/.RegisterActivity } 
01-16 18:13:56.002: W/ActivityManager(51): Launch timeout has expired, giving up wake lock! 
01-16 18:13:56.073: W/ActivityManager(51): Activity idle timeout for HistoryRecord{44d9f420 com.anb.eCalculator/.RegisterActivity} 
01-16 18:14:00.764: I/ActivityManager(51): Displayed activity com.anb.eCalculator/.RegisterActivity: 14756 ms (total 14756 ms) 
01-16 18:14:16.317: W/KeyCharacterMap(241): No keyboard for id 0 
01-16 18:14:16.317: W/KeyCharacterMap(241): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 
01-16 18:14:18.587: D/ViewFlipper(91): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false 
01-16 18:14:18.587: D/ViewFlipper(91): updateRunning() mVisible=true, mStarted=false, mUserPresent=true, mRunning=false 
+0

我無法從Web服務獲得結果。我是android開發新手。我懷疑我的代碼是否有錯誤的Web服務請求。任何人都會指導我。 – Prakash 2012-01-16 12:39:34

+0

您發佈Logcat輸出的異常情況。 – 2012-01-16 12:42:05

+0

我得到一個空指針異常。 – Prakash 2012-01-16 12:47:42

回答

0

@Prakash看看下面的代碼,它調用從活動Web服務

public class FirstAppUI extends Activity 
{ 

    private static final String NAMESPACE = "test.org"; 
    private static final String URL = 
    "http://localhost:8080/AndriodBackend/services/listServices/server-config.wsdd";  
    private static final String SOAP_ACTION = "Test"; 
    private static final String METHOD_NAME = "rate"; 

    private static final String[] sampleACTV = new String[] {"android", "iphone", blackberry"}; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     ArrayAdapter<String> arrAdapter = new ArrayAdapter<String> 
     (this, android.R.layout.simple_dropdown_item_1line, sampleACTV); 

     AutoCompleteTextView ACTV = (AutoCompleteTextView)findViewById 
         (R.id.AutoCompleteTextView01); 
     ACTV.setAdapter(arrAdapter); 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);   
     SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11); 

     envelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

     try { 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
      SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
      ACTV.setHint("Received :" + resultsRequestSOAP.toString()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

我希望這會對你有所幫助。如果有幫助,請接受答案。 – OnkarDhane 2012-01-16 12:52:03

+0

它看起來不同...你可以plz幫我編輯我的代碼以獲得正確的結果... – Prakash 2012-01-16 13:00:32

0
SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 

if (!response.toString().equals("false")) 
     result = true; 

嘗試使用它後面可能會解決你的問題。

SoapObject resultRequestSOAP = (SoapObject) envelope.bodyIn; 

String resultString = resultRequestSOAP.getProperty(0).toString(); 

resultString你將得到結果爲真或假。

+0

我們可以得到布爾結果嗎? – Prakash 2012-01-16 13:06:22

+0

一旦你從服務器得到結果,你可以設置布爾標誌取決於你的條件。據我瞭解你的問題,如果從服務器的結果是假的,你可以設置標誌爲真,否則你可以設置標誌爲假。 – Sumant 2012-01-16 13:11:06

+0

好的..你可以指導我嗎?如何獲得點擊事件的價值? – Prakash 2012-01-16 13:16:32