Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:53+00:00 2026-05-25T22:09:53+00:00

I have a RESTful web service that returns JSON-serialized data. It can successfully serialize

  • 0

I have a RESTful web service that returns JSON-serialized data. It can successfully serialize a Dictionary<string, string> object, but I would like each function to be able to return Dictionary<string, object>.

When I return Dictionary<string, string>, I get the expected JSON response. But when I try to return Dictionary<string, object>, I get this response:

ReadResponse() failed: The server did not return a response for this
request.

So, ON TO THE CODE! Here is the Dictionary<string, object> code that fails:

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Dictionary<string, object> Test(String Token, String Id)
{
    Dictionary<string, object> testresults = new Dictionary<string, object>();
    testresults.Add("Test1Key", "Test1Value");

    Dictionary<string, string> innertestresults = new Dictionary<string, string>();
    innertestresults.Add("InnerTest1Key", "InnerTest1Value");
    innertestresults.Add("InnerTest2Key", "InnerTest2Value");

    testresults.Add("Test2Key", innertestresults);

    return testresults;
}

And, just for kicks/reference, here is the Dictionary<string,string> code that works perfectly:

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public Dictionary<string, string> Test(String Token, String Id)
{
    Dictionary<string, string> testresults = new Dictionary<string, string>();
    testresults.Add("Test1Key", "Test1Value");
    testresults.Add("Test2Key", "Test2Value");
    testresults.Add("Test3Key", "Test3Value");

    return testresults;
}

If anybody has any ideas of how to get this to work (or any alternative ways of doing this to get the same end result), please do let me know! I’m pretty open on how to do this.

On the topic of usage… the reason I need the mix is so that I can return results like this (where the “Data” part could be ANYTHING… not necessarily something with the keys ID, Type, and MaxUsers):

{"Status":"Success","Data":{"ID":"1234","Type":"Live","MaxUsers":"5"}}
{"Status":"Failure","Error":"ID does not exist"}

Thank you all very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:09:53+00:00Added an answer on May 25, 2026 at 10:09 pm

    I can recreate the error you are experiencing but have had no luck getting the service to serialize the Dictionary<string, object> object automatically.

    One workaround is to serialize the object in code using the JavaScriptSerializer class and return the resulting string like so:

    using System.Web.Script.Serialization;
    
    ...
    
    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    public string Test(String Token, String Id)
    {
        Dictionary<string, object> testresults = new Dictionary<string, object>();
        testresults.Add("Test1Key", "Test1Value");
    
        Dictionary<string, string> innertestresults = new Dictionary<string, string>();
        innertestresults.Add("InnerTest1Key", "InnerTest1Value");
        innertestresults.Add("InnerTest2Key", "InnerTest2Value");
    
        testresults.Add("Test2Key", innertestresults);
    
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        string json = serializer.Serialize(testresults);
    
        return json;
    }
    

    Hope this helps.

    Edit (based on comments)

    Ok, spent a little time researching this and it seems as though you need to explicity declare the types that will be present in the object graph when serialization occurs using the ServiceKnownType attribute.

    The ServiceKnownType needs to be added as an attribute of your service and in your case you need to declare the Dictionary<string, string> type like so:

    [ServiceKnownType(typeof(Dictionary<string, string>))]
    [ServiceContract(Namespace = "WebApplication1")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a restful web service which can deal with DTOs in json format
I have a simple web service I wrote using Webmatrix that returns data in
I have an ASP.NET MVC3 Restful web service that uses the Microsoft JSON serializer.
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
I have a web service site that is restful enabled, so other websites/ajax script
I have a ReSTful web service which needs to parse locale-sensitive data from the
I have a restful WCF service that is returning JSON. I was wondering how
I have a simple RESTful web service that print Hello World ! I'm using
I would like to create a RESTful web service that I can deploy on
I've implemented a Spring RESTful web service. Using Jackson JSON for Object Mapping. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.