簡體   English   中英

使用Json在Android客戶端和WCF服務之間傳遞DateTime作為參數

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

我正在嘗試從WCF服務獲取以Android作為客戶端的DateTime(Joda DateTime)篩選的對象列表。 我正在使用Json和REST進行請求。

如何傳遞datetime值作為參數?

就像是:

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

和這個:

[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