0

I am running a WCF service with these methods,

public string UploadInspections(Inspection[] inspections) public string UploadInspection(Inspection inspection) [DataContract] public partial class Inspection { [DataMember] public DateTime DateTime { get; set; } [DataMember] public int Id { get; set; } [DataMember] public string Comment { get; set; } [DataMember] public int Rating { get; set; } } 

From javascript I tried to call a POST on these methods using JSON. The JSON I had for the UploadInspection method was this,

{"Id":10,"Comment":"New One","Rating":3} 

The UploadInspection method was called, but the inspection object was set to null.

I wasn't sure how to specify the Date field using JSON, and I thought that perhaps the parser didn't like JSON with no Date field. I removed the Date field from the Inspection object, but the same thing happened.

Also what should the JSON look like for the UploadInspections method which is an array? I had some JSON that I tried,

"inspections": [{"Id":10,"Comment":"New One","Rating":3}] 

And also this,

[{"Id":10,"Comment":"New One","Rating":3}, {"Id":11,"Comment":"New Two","Rating":2}] 

But I was getting this error,

OperationFormatter encountered an invalid Message body. Expected to find an attribute with name 'type' and value 'object'. Found value 'string'. 

1 Answer 1

9

The problem is not what I thought it was, in my service definition it initially looked like this,

[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] [OperationContract] string UploadInspections(Inspection[] inspections); 

Once I removed this,

BodyStyle = WebMessageBodyStyle.WrappedRequest 

It worked!

Sign up to request clarification or add additional context in comments.

1 Comment

That is 4 hours of my life and multiple clumps of my hair that I can never get back. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.