I've hit a brickwall. My REST implementation won't accept Nullable values.
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Transactions?AccNo={AccNo}&CostCentreNo={CostCentreNo}&TransactionType={TransactionType}&Outstanding={Outstanding}&CheckStartDate={CheckStartDate}&CheckEndDate={CheckEndDate}")]
List<Transactions> GetTransactions(Int32 AccNo, Int32 CostCentreNo, Int32 TransactionType, Boolean Outstanding, DateTime? CheckStartDate, DateTime? CheckEndDate);
Whereas my original SOAP implementation does. So is there a way around this? Or do I have to re-write my code?
I still don't quite get why a datetime must be nullable anyway to be set to null.
Variables for UriTemplate query values must have types that can be converted by QueryStringConverter. Nullable types is not.
You could wrap the parameters and pass it through POST as such;
[DataContract(Name = "Details", Namespace = "")]
public class Details
{
[DataMember]
public Int32 AccNo;
[DataMember]
public Int32 CostCentreNo;
[DataMember]
public Int32 TransactionType;
[DataMember]
public Boolean Outstanding;
[DataMember]
public DateTime? CheckStartDate;
[DataMember]
public DateTime? CheckEndDate;
public Details()
{}
}
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/Transactions",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
List<Transactions> GetTransactions(Details details);
Opionally, you could pass the date as strings instead of DateTime, and then use DateTime.Parse() on the string on the receiving end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With