Attilah
Attilah

Reputation: 17930

how to submit datetime parameter to a WCF REST service

I have a WCF Data service operation :

[WebGet]
public bool isContractUpToDate(string contractId, string lastmodifiedDate);

but I don't know how to call this service from a .NET client application and how I can call this operation from Internet Explorer. I'm looking for some examples.

Upvotes: 5

Views: 13964

Answers (5)

Dr Alex
Dr Alex

Reputation: 21

This is how you can call it according to MSDN

http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders?$filter=ShippedDate gt datetime'1997-09-22T00:00:00'


datetime'1997-09-22T00:00:00

Upvotes: 0

This works for me:

?startDate=2014-04-11T14:45:00&endDate=2014-05-31T23:59:59

I'm using this string to send url parameters to a REST service hosted in ASP.NET application.

Upvotes: 0

Attilah
Attilah

Reputation: 17930

I finally found an answer to my question. to invoke the operation from the browser, I use :

   http://localhost:8080/service/ctrService.svc/isContractUpToDate?contractId='1'&lastmodifieddate='2012/02/04 00:00:00'

and to do it from a .NET client, I use :

    IEnumerable<bool> resp = service.Execute<bool>(new Uri("http://localhost:8080/pricingservice/PricingDataService.svc/isContractUpToDate?contractId='1'&" +"lastmodifieddate='"+DateTime.Now.ToString()+"'"));

        Console.WriteLine("is contract uptodate ? " + resp.First());

Upvotes: 0

Anuraj
Anuraj

Reputation: 19598

We can access RESTful WCF browser services like this

http://localhost:8080/Service/isContractUpToDate/{contractId}/{lastmodifiedDate}

But I think we can't specify DateTime datatype, as per my understanding it should be string only.

Upvotes: 2

dkackman
dkackman

Reputation: 15549

I have found this series to be extremely helpful and rich with examples on how to implement WCF REST services (including query strings and filters as well as calling from client code).

Upvotes: 1

Related Questions