Javascript 将JSON发布到WCF REST端点

Javascript 将JSON发布到WCF REST端点,javascript,json,wcf,rest,Javascript,Json,Wcf,Rest,我正在为我的服务实现PUT、POST和DELETE。但每次我尝试向服务器发送一些json时,都会出现错误“无法创建抽象类”。我通过运行DataContractJsonSerializer、添加_type字段并将其包装在{“obj”:mydata}中来生成请求数据 我可以通过一个DataContractJsonSerializer来运行它,它需要一个BaseObj,并且工作正常: {"__type":"RepositoryItem:http:\/\/objects\/","Insert_date

我正在为我的服务实现PUT、POST和DELETE。但每次我尝试向服务器发送一些json时,都会出现错误“无法创建抽象类”。我通过运行
DataContractJsonSerializer
、添加_type字段并将其包装在{“obj”:mydata}中来生成请求数据

我可以通过一个
DataContractJsonSerializer
来运行它,它需要一个BaseObj,并且工作正常:

 {"__type":"RepositoryItem:http:\/\/objects\/","Insert_date":null,"Modified_date":null,"insert_by":null,"last_modify_user_id":null,"modified_by":null, "external_id":"1234","internal_id":54322,"school_id":45,"type_name":0, "vendor_id":57}
我的服务合同使用
ServiceKnownType
属性进行修饰,列表中包括
RepositoryItem
BaseObj

我正在使用jquery发布

        $.ajax({
            type: "POST",
            url: "http://localhost/slnSDK/service.svc/create/repositoryitem.json?t=" + token, 
            data: data, 
            success: function(result) {
                $("#input").html(result);
            },
            error: function(xhr, result, err) {
                $("#htmloutput").html(xhr.responseText);
            },
            dataType: "json",
            contentType: "application/json"
        });
我暴露了以下端点:

<OperationContract(Action:=Api2Information.Namespace & "createJson")> _
<WebInvoke(Method:="POST", _
           BodyStyle:=WebMessageBodyStyle.Bare, _
           RequestFormat:=WebMessageFormat.Json, _
           responseFormat:=WebMessageFormat.Json, _
           UriTemplate:="/create/{objType}.json?t={token}")> _
Function createJson(ByVal objType As String, ByVal obj As BaseObj, ByVal token As String) As Integer

你能提供的任何帮助都会很好。谢谢

信息量很大,但远程调试总是很困难,以下几点提示:

删除了提琴提示(我可以看到您正在使用它)

在您的ajax帖子中:

    success: function(result) {
        $("#input").html(result);
    },
您应该使用result.d来获取消息内容

    success: function(result) {
        $("#input").html(result.d);
    },

在调试消息中,insert_by字段为null,从片段来看,它看起来不为null是可接受的(作为字符串?而不是字符串)。

我更新了我的帖子以反映这一点,但HTTP请求是使用Fiddler捕获的。另外,感谢大家对返回数据的关注。更新后的答案,空字段有问题吗?嗯。我用空字符串字段中的值再试了一次,没有骰子。
    success: function(result) {
        $("#input").html(result);
    },
    success: function(result) {
        $("#input").html(result.d);
    },