2013-03-26 66 views
2

在我的應用程序中,如果結果成功,我想聯繫web服務並返回一個布爾值。我出於安全原因解析了5個字段,但我不知道如何使用soap發送和接收輸入和輸出。我跟着一個w3school的例子,它用一個輸入工作正常,但現在我對幾個數據感到困惑。請幫助,這是我的代碼。Soap使用5個參數登錄android

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
SoapObject loginTo = new SoapObject(NAMESPACE, "LoginDetail"); 

PropertyInfo pi = new PropertyInfo(); 
loginTo.addAttribute("idCon", "124059432"); 
loginTo.addProperty("codeSession", "1234"); 
loginTo.addProperty("type","CLIENT"); 
loginTo.addProperty("client_number","167"); 
loginTo.addProperty("account_num","3403"); 
loginTo.addProperty("codeAuth","333"); 

request.addProperty("loginDetails", loginTo); 

Log.e("Soap Request : ", "" + request); 

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

HttpTransportSE aht = new HttpTransportSE(URL); 

try { 
    aht.call(SOAP_ACTION, envelope); 
    SoapObject response = (SoapObject) envelope.getResponse(); 

    Log.e ("login result", response.toString()); //lblResult.setText(results.toString()); 

    Boolean loginStatus = Boolean.getBoolean(response.getProperty("success").toString()); 

} catch (Exception e) { 
    e.printStackTrace(); 
} 
+0

嗨。你爲什麼使用兩個SoapObject? – Nirmal 2013-03-26 12:36:02

+0

我看到一個新的例子,所以我想示例 – yakusha 2013-03-26 12:50:11

+0

好的。你有沒有試過我的答案。 – Nirmal 2013-03-26 12:53:46

回答

0
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 


request.addProperty("codeSession", "1234"); 
request.addProperty("type","CLIENT"); 
request.addProperty("client_number","167"); 
request.addProperty("account_num","3403"); 
request.addProperty("codeAuth","333"); 

Log.e("Soap Request : ", "" + request); 

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

HttpTransportSE aht = new HttpTransportSE(URL); 

try 

{ 
    aht.call(SOAP_ACTION, envelope); 
    SoapObject response = (SoapObject) envelope.getResponse(); 

    Log.e ("login result", response.toString()); //lblResult.setText(results.toString()); 

    Boolean loginStatus = Boolean.getBoolean(response.getProperty("success").toString()); 

} 

使用這樣的。希望它能起作用。

+0

SoapFault - faultcode:'soap:Client'faultstring:'Unmarshalling Error:unexpected element(uri:... – yakusha 2013-03-26 13:26:58

+0

請發佈您的完整代碼,我需要NAMESPACE,METHOD_NAME,SOAP_ACTION,URL。 – Nirmal 2013-03-26 13:31:17

+0

嗨,我們可以聊天私人嗎? – yakusha 2013-03-27 05:11:43