2

I got into a big problem supporting ISO dateformat with JSON in my WCF Web service ( Framework 4.0 ). I tried a lot, but no luck yet.

Rest Service :

    [WebInvoke(Method = "PUT", UriTemplate = "/{mvnoid}/{OrderID}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    public DataContracts.Feedback InsertOrder(string mvnoid,string OrderID,OrderRequest orderRequest)
    {            

        OrderRequestManager orderProcessor = new OrderRequestManager();
        DataContracts.Feedback feedback = orderProcessor.ProcessOrder(orderRequest);

        return feedback;

    }

This is my object:

[DataContract(Namespace = NamespacesHelper.SCHEMA_NAMESPACE)]
public class OrderRequest
{
    [DataMember(IsRequired = true, Order = 1)]
    public string SystemId { get; set; }

    [DataMember(IsRequired = true, Order = 2)]
    public string OrderType { get; set; }

    [DataMember(IsRequired = true, Order = 3)]
    public DateTime OrderDate { get; set; }

    [DataMember(IsRequired = true, Order = 4)]
    public DateTime OrderScheduleDate { get; set; }

    [DataMember(IsRequired = false, Order = 5)]
    public int UserId { get; set; }


}

This is my JSON Payload

{ "SystemId":"2", "OrderType":"TESTORDER", "OrderDate":"/Date(1255131630400)/", "OrderScheduleDate":"/Date(1255131630400)/", "UserId":150 } And I need this "/Date(1255131630400)/" to be in ISO format "2012-10-30T15:00:00".

I tried this solution too. with creating custom JSON formatter. JSON.NET Serializer for WCF REST Services. But I was unable to find HttpHostConfiguration class anywhere . :(

Thanks in Advance for helping.

Community
  • 1
  • 1
Ruwan Jayalath
  • 361
  • 5
  • 10
  • Just return that date as a string (two fields on your object, or DateTime, one string representation)? – BlueChippy Oct 30 '12 at 08:13
  • I have date field as datetime. – Ruwan Jayalath Oct 30 '12 at 08:18
  • Add another readonly "[DataMember] string xxxDateString {get {return xxxDate.ToString("dd/MMM/yyyy" ;}}" or similar? If OrderDate for example is only coming FROM the back-end, then you don't need to expose this as a DateTime at all to WCF. – BlueChippy Oct 30 '12 at 08:31
  • My service is called by a third party with iso format. I have used this objectrequest class in several other services, so it is not possible to change the contract. – Ruwan Jayalath Oct 30 '12 at 08:34
  • Do you want payload to be in ISO format? What's you client in this case? – Andriy F. Dec 12 '14 at 11:59

0 Answers0