如何通过WCF-RIA-Services JSON端点插入实体 [英] How to insert entity over WCF-RIA-Services JSON endpoint
问题描述
我的WCF-RIA DomainService具有一个如下所示的插入方法:
My WCF-RIA DomainService has an insert method that looks like this:
public void InsertWidget(WidgetDef widgetDef)
class WidgetDef
{
[Key]
int widgetID;
string title;
int x;
int x;
// there are more properties, but I think you get the idea...
}
要通过JSON端点访问此地址,我想我需要将更改集发布到url:
To access this through the JSON endpoint, I think I need to POST a changeset to the url:
[serverURL] [namespace] WidgetService.svc/json/SubmitChanges.
[serverURL][namespace]WidgetService.svc/json/SubmitChanges.
我很确定我的URL正确,因为我的请求到达了WidgetService.Initialize方法,但是随后我在服务器中得到一个异常-这并不奇怪,因为我不知道请求的内容是什么应该看起来像.
I'm pretty sure I got the URL correct, because my request reaches the WidgetService.Initialize method, but then I get an exception in the server - which is no surprise because I don't know what the content of the request should look like.
我的问题:用于插入操作的HTTP请求内容的(JSON)格式是什么?
My Question: What is the (JSON) format of a HTTP request's content for an insert operation?
推荐答案
为给定示例插入更改集将如下所示:
Insert changeset for the example given would look like this:
{"changeSet":[
{"Id":0,
"Entity":{"__type":"WidgetDef:#widgetDefNamespace",
"widgetId":0,
"title":"the new title",
"x":10,
"y":10,
},
"Operation":2 // '2' for insert, '3' for update, '4' for delete
}
]
}
感谢以下博客文章: http://www.joseph-connolly.com/blog/post/WCF-RIA-Services-jQuery-and-JSON-endpoint-Part-2.aspx
这篇关于如何通过WCF-RIA-Services JSON端点插入实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!