Reputation: 97
So I have the following service:
public interface IService1
{
[OperationContract, WebGet(UriTemplate = "/getStuff?stuff={stuff}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
List<Row> getdTable(string stuff);
[OperationContract, WebInvoke(UriTemplate = "/log", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST")]
void insertLog(Log[] log);
[OperationContract, WebInvoke(UriTemplate = "/testPost", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST")]
void testPost(TwoStrings testPost);
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[DataContract]
public class TwoStrings
{
[DataMember]
public string one { get; set; }
[DataMember]
public string two { get; set; }
}
The WebGet works like a charm, but I can't get any of the webinvoke methods to actually work. I'm testing it using fiddler right now, using the following POST:
POST http://localhost:50051/Service1.svc/testPost HTTP/1.1
Host: localhost:50051
User-Agent: Fiddler
Content-Type: application/json; charset=utf-8
Content-Length: 25
{"testPost":{"one":"test1","two":"test2"}}
And the response I get back is:
HTTP/1.1 400 Bad Request
I'm at a loss here, I've tried several different formats on the JSON body to no avail. Is the JSON properly formatted? Is there any configuration required to do a POST?
edit: Solution found, I'm an IDIOT. The last time I corrected the fiddler request to reflect the proper body wrapping I forgot to alter the body size from 25 to the correct 38. Thanks for the quick responses!
Upvotes: 3
Views: 4188