Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a problem about WCF web service POST operation contract.

If I send my json string like this(bare), I get bad request(400) error. If I wrapped this json string, then empty object will came to method.

{"WorkCommandNumber":"F999/1","BLPProductCode":"F999","ReceivedOrderNumber":16,"GroupNumber":1,"WorkCommandOpenDate":"2017-12-04T23:00:00+02:00","RevisionCode":"R0","DeliveryLocation":"LOCATION XYZ","DueDate":"2018-01-09T00:00:00+02:00","ShippingDate":null,"Notes":"Test Note","WorkCommandDocuments":[],"WorkCommandProblems":[],"WorkCommandProductionConsignments":[],"WorkCommandProductionProcesses":[{"ID":20,"ProductionProcessCode":"APPROVAL","CompanyCode":"BLP","WorkCommandNumber":"F999/1"}],"WorkCommandProductions":{"WorkCommandNumber":"F999/1","ProductionMaterial":"PLASTIC","ProductionStartDate":"2017-12-04T00:00:00+02:00","ProductionFinishDate":null,"MoldKnifeStockCode":null},"WorkCommandProductionTools":[],"WorkCommandSubProducts":[]}


Can you help me about this issue?

Thank you.

EDIT: The issue was .NET Json Serializer serializes the Date's ISO format.("2017-12-04T00:00:00+02:00")
But the WCF service can't convert this Date format, and it gets null or empty object.
When I change the Date format form ISO formatting to Windows formatting the problem solved.

What I have tried:

My Operation Contract;

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/UpdateWorkCommand")]
string UpdateWorkCommand(WorkCommand WorkCommandToUpdate);


Tryings;
1- Set BodyStyle = WebMessageBodyStyle.Bare and send bare json string. (400 Bad Request)
2- Set BodyStyle = WebMessageBodyStyle.Bare and send wrapped json string. (Empty object comes(not null))
3- Set BodyStyle = WebMessageBodyStyle.Wrapped and send wrapped json string.(400 Bad Request)
4- Set BodyStyle = WebMessageBodyStyle.Wrapped and send bare json string.(Null object comes)

public string UpdateWorkCommand(WorkCommand WorkCommandToUpdate)
{ 
     // Some Code
}


I'm calling this service method with JSON string using Postman.

P.S: I set the header's content-type to "application-json"
Posted
Updated 8-Feb-18 8:17am
v4
Comments
dan!sh 7-Feb-18 1:15am    
I assume you have configured required binding for WCF service. Can you check if your payload has correct property names and data types?
Onur ERYILMAZ 7-Feb-18 1:35am    
I check that and I found out that the problem is my Date properties, if I send my json like this;

{"WorkCommandNumber":"F999/1","BLPProductCode":"F999","ReceivedOrderNumber":16,"GroupNumber":1}

The object's properties perfectly setting, but when I add the Date like this;

{"WorkCommandNumber":"F999/1","BLPProductCode":"F999","ReceivedOrderNumber":16,"GroupNumber":1,"WorkCommandOpenDate":"2017-12-04T23:00:00+02:00"}

I get bad request error.

How to solve that?
Richard Deeming 8-Feb-18 12:51pm    
The fact that your question is solved is not immediately obvious. You should post your edit as a solution, and mark it as accepted. :)

1 solution

The issue was .NET Json Serializer serializes the Date's ISO format.("2017-12-04T00:00:00+02:00")
But the WCF service can't convert this Date format, and it gets null or empty object.
When I change the Date format form ISO formatting to Windows formatting the problem solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900