简体   繁体   English

使用Json在Android客户端和WCF服务之间传递DateTime作为参数

[英]Passing DateTime as a parameter between android client and WCF Service using Json

I'm trying to get a list of objects filtering by DateTime (Joda DateTime) with android as client, from a WCF Service. 我正在尝试从WCF服务获取以Android作为客户端的DateTime(Joda DateTime)筛选的对象列表。 I'm using Json and REST to do the request. 我正在使用Json和REST进行请求。

How can I pass the datetime value as a parameter? 如何传递datetime值作为参数?

Something like: 就像是:

HttpPost request = new HttpPost( SERVICE_URI + "/GetScheduleEntrysByDate/" + date.toString());

And this: 和这个:

[OperationContract]
[WebInvoke(Method = "POST",
    UriTemplate = "GetScheduleEntrysByDate/{date}",
    BodyStyle = WebMessageBodyStyle.WrappedRequest,
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json)]
List<ScheduleEntry> GetScheduleEntrysByDate(DateTime date);
// you might wanna specify custom params here for the DefaultHttpClient contructor
DefaultHttpClient httpClient = new DefaultHttpClient();

HttpPost request = new HttpPost( SERVICE_URI + "/GetScheduleEntrysByDate/" + date.toString());

List<NameValuePair> bodyParams = new ArrayList<NameValuePair>();
bodyParams.add(new BasicNameValuePair("date", new Date().getTime());
if (bodyParams.size() > 0) {
    try {
        // Include the request body
        post.setEntity(new UrlEncodedFormEntity(bodyParams));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Body parameters produced unsupported encoding?", e);
    }
}
// sends the POST with params,  you will need to put this in a try catch
try {
    HttpResponse httpResponse = httpClient.execute(request);
} catch (Exception e){
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM