发送列表<object> WCF POST

时间:2017-03-27 05:59:29

标签: c# wcf

有谁能告诉我如何在WCF POST方法中将List作为输入参数发送?

我有一个这样的课程:

    public class CreateBudget
    {
        [DataMember]
        public string pr_code { get; set; }

        [DataMember]
        public List<BudgetTransactionRequest> transactions { get; set; } 

    }
    [DataContract(Namespace = "http://mlpt-web.com/CRM/services")]
        public class BudgetTransactionRequest
        {
            [DataMember]
            public string transaction_code { get; set; }
            [DataMember]
            public double? amount { get; set; }
        }

[OperationContract]是这样的:

[OperationContract]
        [WebInvoke(Method = "POST",
         ResponseFormat = WebMessageFormat.Json,
         RequestFormat = WebMessageFormat.Json,

         UriTemplate = "/CreateBudget"
         )]
        void CreateTransactions(CreateBudget cbreq);

我尝试使用以下字符串使用fiddler测试调用:

    {
"CreateBudget":{"pr_code": "AFK"},
"Transactions":[{"transaction_code":"PRS-0001", "amount": 2000.000},{"transaction_code":"PRS-0002", "amount": 3000.000} ]
}

我收到http 400错误(错误的请求错误)。想法?

1 个答案:

答案 0 :(得分:0)

你可以查一下。

{
 "pr_code": "AFK",
"Transactions":[{"transaction_code":"PRS-0001", "amount": 2000.000},{"transaction_code":"PRS-0002", "amount": 3000.000} ]
}

希望它对你有用。