I have an android project working with a wcf service. I send an object as a parameter in Select type in java side. But it didn't match with it's C# class. It is always null
in wcf side.
Here is my Select function :
Select select = new Select();
select.setOrderBy(Select.OrderBy.Desc);
select.setOrderColumn("CategoryName");
select.setTop(3);
Where where = new Where();
where.setColumn("ID");
where.setValue("3");
where.setOperators(Where.Operators.GreaterEqual);
jsonObject.put("select", select);
jsonObject.put("where", where);
new TDJson(jsonObject, new TDJsonListener() {
@Override
public void successCallBack(String jsonResult) {
try {
JSONObject json = new JSONObject(jsonResult);
.
.
.
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void errorCallBack() {
}
}, true).execute("http://address/Service/Select");
This is my TDJson code :
try {
HttpParams httpParams = new BasicHttpParams();
HttpClient httpClient = new DefaultHttpClient(httpParams);
HttpPost httpPost = new HttpPost(params[0]);
if (jsonObj != null) {
if (!jsonObj.toString().equals("")) {
httpPost.setEntity(new StringEntity(jsonObj.toString(), "UTF-8"));
}
}
httpPost.setHeader("Accept", "application/jsonStr");
httpPost.setHeader("Content-type", "application/jsonStr; charset=utf-8; ");
httpPost.setHeader("Cache-Control", "max-age=600");
HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
HttpConnectionParams.setSoTimeout(httpParams, 5000);
HttpResponse response = httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == HttpsURLConnection.HTTP_OK) {
jsonResult = EntityUtils.toString(response.getEntity());
} else {
jsonResult = "error";
}
} catch (IOException e) {
jsonResult = "error";
}
return jsonResult;
This is my Select class in java :
public class Select {
public Integer top;
public String orderColumn;
public OrderBy orderBy;
public String[] columns;
public Integer getTop() {
return top;
}
public String getOrderColumn() {
return orderColumn;
}
public OrderBy getOrderBy() {
return orderBy;
}
public String[] getColumns() {
return columns;
}
public void setTop(Integer top) {
this.top = top;
}
public void setOrderColumn(String orderColumn) {
this.orderColumn = orderColumn;
}
public void setOrderBy(OrderBy orderBy) {
this.orderBy = orderBy;
}
public void setColumns(String[] columns) {
this.columns = columns;
}
public enum OrderBy {
Asc,
Desc
}
}
And this one is my Select class in C# :
[DataContract]
public class Select
{
public Select()
{
top = -1;
orderColumn = null;
orderBy = OrderBy.Asc;
columns = null;
}
[DataMember]
public Int32 top { get; set; }
[DataMember]
public String orderColumn { get; set; }
[DataMember]
public OrderBy orderBy { get; set; }
[DataMember]
public String[] columns { get; set; }
[DataContract]
public enum OrderBy
{
[EnumMember]
Asc,
[EnumMember]
Desc
}
}
And this one is also my wcf code (Select object is always null
here) :
public List<CategoryData> Select(Select select, Where where)
{
Table<Category> table = new Table<Category>();
.
.
.
}
I just changed these lines
httpPost.setHeader("Accept", "application/jsonStr");
httpPost.setHeader("Content-type", "application/jsonStr; charset=utf-8; ");
to
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json; charset=utf-8; ");
and it worked :)