WCF Rest API:如何使用邮递员发送字典 [英] WCF Rest API: How to sent dictionary using postman

查看:41
本文介绍了WCF Rest API:如何使用邮递员发送字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下界面&执行.

I have following interface & implementation.

** Interface **
public interface IAPIHelper
{
    //RESTFul API
    [FaultContract(typeof(RequestValidationFault))]
    [WebInvoke(UriTemplate = "/ByteFromData", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    [OperationContract]
    byte[] ByteFromData(ByteFaRequest HashMap);
}

 *** Data contract ***

[DataContract]
public class ByteFaRequest 
{
    [DataMember]
    public Dictionary<string, string[]> HashMap;
}


  ***Implementation****

[ServiceBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class APIHelper : IAPIHelper
{
    public byte[] ByteFromData(ByteFaRequest data)
    {
        // Business Logic
    }
}

现在,我正在尝试使用邮递员检查此 api,但我没有在参数中获得任何值,尽管我可以调用其他获取/发布 WCF REST api.我在邮递员中创建 JSON 请求时遗漏了什么吗?

Now, I am trying to check this api using postman, but i did not get any value in parameter, though i am able to call other get/post WCF REST apis. Do i missing something in creating JSON request in postman.

 json request - 
 {
   "HashMap" : {"key1":["1.1","1.2"],"key2":["2.1","2.2"],"key3":["3.1","3.2"]}
 }

邮递员截图:

[![在此处输入图片描述][1]][1]

[![enter image description here][1]][1]

调用 api 后 - 我没有在字典对象中获取数据.

After calling api - i did not get data in dictionary object.

json 请求中缺少什么?

what is missing in json request?

推荐答案

应该是一个以属性为键值的数组尝试以下请求

It should be like an array with attribute as key and value try below request

{
   "HashMap" : [
                {"key": "key1", "value": ["1.1","1.2"]},
                {"key": "key2", "value": ["2.1","2.2"]}
               ]
 }

这篇关于WCF Rest API:如何使用邮递员发送字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆