0

我已将此代码提交给服务器:

var obj = { "param": { "WithdrawalRequestId": window.Xrm.Page.data.entity.getId()} };
    $.ajax({
        type: "POST",
        dataType: "json",   
        data: JSON.stringify(obj),

        url: crmConfig.service + '/WithdrawRequestService.svc/ExecuteWithdrawalRequests/',

    });

到服务器的实际内容是:

{"param":{"WithdrawalRequestId":"{628E2E3A-283A-E311-B658-005056B7032A}"}}

界面:

 [OperationContract]
        [WebInvoke(Method = "POST",
            RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "/ExecuteWithdrawalRequests/")]
        void ExecuteWithdrawalRequests(GuidParameter param);

GuidParameter 类:

[DataContract]
public class GuidParameter
{
    [DataMember]
    public Guid WithdrawalRequestId { get; set; }

}

我收到以下错误:

The server encountered an error processing the request. 

异常消息是“传入消息具有意外消息格式“原始”。
该操作的预期消息格式为“Xml”、“Json”。这可能是因为尚未在绑定上配置 WebContentTypeMapper。
有关详细信息,请参阅 WebContentTypeMapper 的文档。

这是铬输出:

`Request URL:http://crm3:81/WithdrawRequestService.svc/ExecuteWithdrawalRequests/
Request Method:POST
Status Code:500 General Error. Please contact support team.
Request Headersview source
Accept:application/json, text/javascript, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:74
Content-Type:application/x-www-form-urlencoded
Host:crm3:81
Origin:http://crm3
Pragma:no-cache
Referer:http://crm3/CRN/userdefined/edit.aspx?_gridType=10019&etc=10019&id=%7b628E2E3A-283A-E311-B658-005056B7032A%7d&pagemode=iframe&rskey=292691624
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Form Dataview sourceview URL encoded
{"param":{"WithdrawalRequestId":"{628E2E3A-283A-E311-B658-005056B7032A}"}}:
Response Headersview source
Access-Control-Allow-Headers:Content-Type, Accept
Access-Control-Allow-Methods:POST
Access-Control-Allow-Origin:*
Cache-Control:private
Content-Length:2738
Content-Type:text/html
Date:Mon, 28 Oct 2013 07:35:33 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET`
4

2 回答 2

3

添加 contentType: "application/json,

var obj = { "param": { "WithdrawalRequestId": window.Xrm.Page.data.entity.getId()} };
    $.ajax({
        type: "POST",
        dataType: "json",   
        data: JSON.stringify(obj),
        contentType: "application/json",
        url: crmConfig.service + '/WithdrawRequestService.svc/ExecuteWithdrawalRequests/',

    });
于 2013-10-28T09:29:05.903 回答
0

如果您是初学者,那么这将指导您创建支持 json 和 xml 的 Web 服务,供以下用户使用:

创建 RESTful WCF 服务 API:分步指南

更新:

WCF“原始”编程模型(Web) - 接收任意数据

或者

创建和使用 JSON 格式的 OData

于 2013-10-28T08:51:19.343 回答