Within WCF services, there are many different return types that you can use in order to get data from different dependencies within a service. One problem, though, when working with WCF you might run into, is that WCF doesn’t support usage of a Dictionary as a return type. Although there are many reasons for this (which I will not go into now), but there are also different ways of dealing with this. All the examples I found online seemed like reasonable options, but I also had a different idea.
Since WCF allows for a List return type, why not convert a dictionary to a list, return it, and convert it back into a dictionary? Having two methods, one that converts from a dictionary to a list, and another that converts back, would make this very easy to do.
Below are two methods for doing just this!
So, how do we test this? Pretty simple… just create a new dictionary with some values, send it through both, and debug to see what the values are. Here is an example of the pageload of an aspx form:
So, once we setup a debug point, and run our project, it should stop at the end of the Page_load function. Once running, we can see that the values come through, no problem.
Although I implemented this with a string and integer, since Dictionary is a generic class, you can specify whatever types you need to implement. You will then need to modify the functions to support your desired data-type.