WCF Rest API:如何使用邮递员发送字典
WCF Rest API: How to sent dictionary using postman
我有以下接口和实现。
** 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,但我没有在参数中获得任何值,尽管我可以调用其他 get/post WCF REST api秒。我在邮递员中创建 JSON 请求时遗漏了什么吗?
json request -
{
"HashMap" : {"key1":["1.1","1.2"],"key2":["2.1","2.2"],"key3":["3.1","3.2"]}
}
POSTMAN 截图:
[![在此处输入图片描述][1]][1]
调用 api 后 - 我没有在字典对象中获取数据。
json 请求中缺少什么?
应该是一个以属性为key和value的数组
试试下面的请求
{
"HashMap" : [
{"key": "key1", "value": ["1.1","1.2"]},
{"key": "key2", "value": ["2.1","2.2"]}
]
}
我有以下接口和实现。
** 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,但我没有在参数中获得任何值,尽管我可以调用其他 get/post WCF REST api秒。我在邮递员中创建 JSON 请求时遗漏了什么吗?
json request -
{
"HashMap" : {"key1":["1.1","1.2"],"key2":["2.1","2.2"],"key3":["3.1","3.2"]}
}
POSTMAN 截图:
[![在此处输入图片描述][1]][1]
调用 api 后 - 我没有在字典对象中获取数据。
json 请求中缺少什么?
应该是一个以属性为key和value的数组 试试下面的请求
{
"HashMap" : [
{"key": "key1", "value": ["1.1","1.2"]},
{"key": "key2", "value": ["2.1","2.2"]}
]
}