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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x