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 3846112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:20:52+00:00 2026-05-19T16:20:52+00:00

I am designing a WCF REST service. A requirement for the design is that

  • 0

I am designing a WCF REST service. A requirement for the design is that the
client is unaware of the particulars of a given request. For example, the
following request:

https://www.domain.com/dashboard/group/id/0

Would return:

Request: GetGroup(GroupId = 0)
Response: 
{
Title="Country",
children = 
{
title="USA", Id=1, type=GROUP},
{title="England", Id=2, type=GROUP}
}
}

And the following request:

https://www.domain.com/dashboard/group/id/3

Would return:

Request: GetGroup(groupId = 3)
Response: 
{
Title="Customers",
children = 
{
title="General Motors", Id=1, type=CUSTOMER},
{title="General Electric", Id=2, type=CUSTOMER}
}
}

MY QUESTION IS how do I take a generic REST request and return a type-specific response?

In my project, there are a few Types that will be serialized in the JSON response. The serialized object depends on the passed-in groupId parameter. They are:

GROUP
CUSTOMER
FACILITY
TANK

In a related post, it was suggested that I create a base class that exposes GetGroupById
and the above classes should override the base class method. If this sounds like a good
example of how to attack this problem, I’d appreciate an example. Or, alternatively, other suggestions.

Thanks in advance.

  • 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-19T16:20:52+00:00Added an answer on May 19, 2026 at 4:20 pm

    You could always create a service that returns a Stream and use the JsonSerializer to serialize your objects into a MemoryStream, and then return the MemoryStream from the service:

    public Stream GetSomeObject(int groupId)
    {
        byte[] bytes;
        var serializer = new JavaScriptSerializer();
    
        switch(groupId)
        {
            case 2:
                var groups = GetGroups(); // fill the groups however
                bytes = Encoding.UTF8.GetBytes(serializer.Serialize(groups));
                break;
            case 3:
                var customers = GetCustomers();
                bytes = Encoding.UTF8.GetBytes(serializer.Serialize(customers));
                break;
        }
    
        return new MemoryStream(bytes);
    }
    

    In that case, you would simply load the appropriate object into memory based on the parameters and return the appropriate strongly typed object via the Stream.

    This is the same approach I’ve used in the past to return Json results from a WCF Service without the type information (the approach was suggested by a member Microsoft’s WCF team, so I figured it was fairly reliable).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am designing a REST service that could be used by many types of
I am designing a WCF service which have some operations that i expose to
I'm designing a WCF service that will return a list of objects that are
I am designing an ASP.NET website, which also provides a WCF service for client
I'm designing a WCF service that will return a response code (such as 0
Let's say that I'm considering designing a WCF service whose primary purpose is to
I am designing a WCF service with callback, but my implementation of the callback
I am designing a WCF service with callback using named pipe binding. And when
I am designing a WCF service using DDD. I have a domain service layer
I am designing a duplex channel wcf service using a custom binding. Currently, when

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.