将数据发送到WCF服务

问题描述 投票:-1回答:1

我正在关注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]
c# android wcf
1个回答
0
投票

不要将PropertyInfo传递给addProperty函数。 代替

request.addProperty("StudentList", pi);

直接添加它

request.addProperty("StudentList", li);
© www.soinside.com 2019 - 2024. All rights reserved.