.net WCF REST服务:请求对象为null

.net WCF REST服务:请求对象为null,.net,wcf,rest,.net,Wcf,Rest,我正在尝试将对象发送到REST服务,但该对象未正确映射 我已将我的合同定义为: <OperationContract(), WebInvoke(UriTemplate:="/SendNotification", ResponseFormat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Bare,

我正在尝试将对象发送到REST服务,但该对象未正确映射

我已将我的合同定义为:

<OperationContract(),
    WebInvoke(UriTemplate:="/SendNotification",
              ResponseFormat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Bare,
              Method:="POST")>
Function SendNotification(ByVal data As Models.Notification) As Boolean
生成的请求如下所示:

POST http://localhost:62530/Services/Notification/NotificationWS.svc/SendNotification HTTP/1.1
Host: localhost:62530
Connection: keep-alive
Content-Length: 87
Cache-Control: no-cache
Pragma: no-cache
Origin: http://localhost:62530
X-Requested-With: XMLHttpRequest
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)         Chrome/33.0.1750.146 Safari/537.36
DNT: 1
Referer: http://localhost:62530/D.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,ca;q=0.6,fr;q=0.4,pt;q=0.2,es;q=0.2

{"data":{"ApplicationID":"2","PortalIDs":"pid","Message":"THis is a test","Badge":"3"}}
函数被调用,并且存在一个数据对象,但其属性为null

我一直在研究类似的问题,比如运气不好


谢谢

尝试更改您发布的数据,如下所示:

var o = {ApplicationID: "2", PortalIDs: "pid", Message: "This is a test", Badge: "3"};

我似乎还记得,当我使用WCF rest时,我从未在HTTP请求中指定过变量名。

我认为将
WebMessageBodyStyle.Bare
更改为
WebMessageBodyStyle.Wrapped
在您的情况下也可以做到这一点。

您能提供Models.Notification类吗?我觉得你的电话没问题,只是更新了问题。谢谢这对我来说很奇怪,你试过通过.net调用你的方法吗?我使用HttpWebRequest或WebClient.No进行了测试。我将尝试显示resultsIf success,然后在fiddler中查看调用是如何构造的。我认为这将是愚蠢的事情。我以前也遇到过这样的问题,而且总是很傻:)
POST http://localhost:62530/Services/Notification/NotificationWS.svc/SendNotification HTTP/1.1
Host: localhost:62530
Connection: keep-alive
Content-Length: 87
Cache-Control: no-cache
Pragma: no-cache
Origin: http://localhost:62530
X-Requested-With: XMLHttpRequest
Content-Type: application/json
Accept: */*
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)         Chrome/33.0.1750.146 Safari/537.36
DNT: 1
Referer: http://localhost:62530/D.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,ca;q=0.6,fr;q=0.4,pt;q=0.2,es;q=0.2

{"data":{"ApplicationID":"2","PortalIDs":"pid","Message":"THis is a test","Badge":"3"}}
var o = {ApplicationID: "2", PortalIDs: "pid", Message: "This is a test", Badge: "3"};