2012-05-21 29 views
2

我試圖將UUID傳遞給Web服務,但是當我嘗試發送每個參數時,它返回一個錯誤,表示無法序列化,然後出現UUID的值,除非我通過它像有一個字符串值是在代碼中,但是當它發送到Web服務它給人的意外類型的文本流讀取錯誤Android:UUID無法序列化

下面的代碼如果你們能幫助我將aprecciate它:

package go.pw.exe; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 

import java.util.Calendar; 
import java.util.UUID; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 

public class Ex1Activity extends Activity { 
    private static final String SOAP_ACTION="http://vitalcare.hydra.pt/IHealthRecordService/CreateWeightRecord"; 
    private static final String METHOD_NAME = "CreateWeightRecord"; 
    private static final String NAMESPACE = "http://vitalcare.hydra.pt/"; 
    private static final String URL = "http://www.hydra.pt:8070/HealthRecordService.svc?wsdl"; 

    Calendar c; 
    String data; 
    TextView msg; 
    UUID weightId; 
    Button send; 
    EditText weight; 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 


     send = (Button) findViewById(R.id.button1); 
     weight = (EditText) findViewById(R.id.et_weight); 

     send.setOnClickListener(new OnClickListener(){ 
      public void onClick(View v) { 


       int userWeight = Integer.valueOf(weight.getText().toString()); 
       c = Calendar.getInstance(); 
       weightId= UUID.randomUUID(); 
       data = c.get(Calendar.YEAR)+ "-" + (c.get(Calendar.MONTH)+1) + "-"+c.get(Calendar.DAY_OF_MONTH)+ " " + c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND); 
       String Id = UUID.randomUUID().toString(); 

       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
       request.addProperty("UserId", "3e1c7765-7370-4295-8170-92a1d2dc542c"); 
       request.addProperty("CreationDate", data); 
       request.addProperty("WeightId", Id); 
       request.addProperty("When", data); 
       request.addProperty("WeightInKilos", userWeight); 

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

       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

       try{ 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
      } 
      catch (Exception e) { 
      e.printStackTrace(); 
      Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show(); 

        } 
       } 
      }); 
     } 
    } 
+0

你能告訴你如何解決你的問題嗎? – user1213202

回答