【问题标题】:Send Data to WCF service向 WCF 服务发送数据
【发布时间】:2014-10-17 03:22:36
【问题描述】:

我正在关注Student 课程,

public class Student implements KvmSerializable {

    private String ID;
    private String Mark;
    private String Percentage;

    public String getID() {
        return FoodItemID;
    }

    public void setID(String ID) {
        ID = ID;
    }

    public String getMark() {
        return Modifier;
    }

    public void setMark(String mark) {
        Modifier = modifier;
    }

    public String getPercentage() {
        return Quantity;
    }

    public void setPercentage(String percentage) {
        Percentage = percentage;
    }

    @Override
    public Object getProperty(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getPropertyCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setProperty(int arg0, Object arg1) {
        // TODO Auto-generated method stub

    }

}

以下签名中的学生名单,

ArrayList<HashMap<String, String>> studentList;

现在我想将此列表发送到 WCF 服务,所以我创建了以下 PropertyInfo 对象,

for (int i = 0; i < studentList.size(); i++) {
    Student items = new Student();
    items.setID(studentList.get(i).get("ID"));
    items.setMark(studentList.get(i).get("Mark"));
    items.setPercentage(studentList.get(i).get("Percentage"));          
    li.add(items);
}
PropertyInfo pi = new PropertyInfo();
pi.setName("StudentList");
pi.setValue(li);
pi.setType(Student.class);

我的要求是

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("StudentList", pi);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.implicitTypes = true;
HttpTransportSE transport = new HttpTransportSE(URL);
try {
    transport.call(SOAP_ACTION, envelope);
} catch (final Exception e) {
    activity.runOnUiThread(new Runnable() {

        public void run() {
            new CustomToast(activity, SOAP_ACTION + " - "
                    + e.getMessage() + " error").show();
            e.printStackTrace();
        }
    });
}
try {
    fault = (SoapFault) envelope.bodyIn;
    activity.runOnUiThread(new Runnable() {

        public void run() {
            if (fault != null) {
                new CustomToast(activity, fault.getMessage())
                        .show();
            }
        }
    });
} catch (Exception e) {
    e.printStackTrace();
}
try {
    result = (SoapObject) envelope.bodyIn;
    System.out.println("result in getdata : " + result);
} catch (Exception e) {
    e.printStackTrace();
}

但这给了我以下异常,

java.lang.RuntimeException: Cannot serialize: StudentList : [com.example.citrusz.Student@410c08f8]

【问题讨论】:

  • 什么时候你得到了异常?
  • 在这一行transport.call(SOAP_ACTION, envelope);

标签: c# android wcf


【解决方案1】:

不要将PropertyInfo 传递给addProperty 函数。
而不是

request.addProperty("StudentList", pi);

直接添加

request.addProperty("StudentList", li);

【讨论】:

  • 现在java.lang.RuntimeException: Cannot serialize: [com.example.citrusz.Student@4107f6c0]@Sam
猜你喜欢
  • 2012-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-03
  • 2010-12-03
相关资源
最近更新 更多