asp.netrestapidictionarywcf-rest

WCF Rest API: How to sent dictionary using postman


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
    }
}

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"]}
 }

POSTMAN Screenshot:

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

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

what is missing in json request?


Solution

  • 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"]}
                   ]
     }