2

我正在尝试将 UUID 传递给 Web 服务,但是当我尝试发送每个参数时,它返回一个错误,指出无法序列化,然后它出现 UUID 的值,除非我将它作为字符串值传递,就像在代码,但是当它发送到 Web 服务时,它给出了意外的类型文本流阅读器错误

如果你们中的任何人可以帮助我,这是代码:

 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();

                  }  
                }
            });
        }
    }
4

0 回答 0