关于JSON的WCF服务POST问题 [英] Wcf service POST issue about json

查看:167
本文介绍了关于JSON的WCF服务POST问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对WCF Web服务POST操作合同有疑问.

如果我像这样(裸露)发送我的json字符串,则会收到错误的request(400)错误.如果我包装了这个json字符串,那么空对象将来到方法中.

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":[]}



您能帮我解决这个问题吗?

谢谢.

问题是.NET Json Serializer序列化日期的ISO格式.("2017-12-04T00:00:00 + 02:00")
但是WCF服务无法转换此Date格式,并且它获取null或空对象.
当我将日期格式从ISO格式更改为Windows格式时,问题解决了.

我尝试过的事情:

我的运营合同;



Can you help me about this issue?

Thank you.

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);



尝试;
1-设置BodyStyle = WebMessageBodyStyle.Bare并发送裸json字符串. (400错误要求)
2-设置BodyStyle = WebMessageBodyStyle.Bare并发送包装的json字符串. (空对象来了(不为null))
3-设置BodyStyle = WebMessageBodyStyle.Wrapped并发送包装的json字符串.(400错误请求)
4-设置BodyStyle = WebMessageBodyStyle.Wrapped并发送裸json字符串.(空对象来了)



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
}



我正在使用邮递员使用JSON字符串调用此服务方法.

PS:我将标头的内容类型设置为"application-json"



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

P.S: I set the header''s content-type to "application-json"

推荐答案

问题是.NET Json Serializer序列化Date的ISO格式.("2017-12-04T00:00:00 + 02:00")
但是WCF服务无法转换此Date格式,并且它获取null或空对象.
当我将日期格式从ISO格式更改为Windows格式时,问题解决了.
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.


这篇关于关于JSON的WCF服务POST问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆