0
votes

I have a .net 4.0 WCF servicing running with the following endpoint:

[OperationContract]
    [WebInvoke(Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "UploadReport")]
    bool UploadReport(Report report);

My client is .net 2.0 and thus can't use [DataContract] on my objects. I'm using Json.net to serialize my data and then send it to the service.

string json = JsonConvert.SerializeObject(report);
        WebRequest request = HttpWebRequest.Create("http://localhost:51605/QBDHandoffService.svc/UploadReport");
        request.Method = "POST";
        request.ContentType = "application/json";

        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            streamWriter.Write(json);
            streamWriter.Close();
        }
        var response = (HttpWebResponse)request.GetResponse();

The call successfully reaches the service but the 'report' is always null. I suspect a serialization issue since I can't stick a [DataContract] on the object on the .net 2.0 side, but wasn't completely sure. The JSON looks good when I send it off, is there something I am missing here? How can I accomplish this? Thanks!

1
Have you used a tool like Fiddler to see what is being sent?TheGeekYouNeed

1 Answers

0
votes

Found the issue was JSON.net serializing the DateTime in a way that WCF didn't like. To fix it I used JsonSerializerSettings:

JsonSerializerSettings dateFormatSettings = new JsonSerializerSettings()
{
    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
};
string json = JsonConvert.SerializeObject(report, dateFormatSettings);