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

  • Home
  • SEARCH
  • 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 6001795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:53:08+00:00 2026-05-23T00:53:08+00:00

I have a web method which calls a method in the DAL to execute

  • 0

I have a web method which calls a method in the DAL to execute a procedure by id and returns an object of type MyData.

[WebMethod]
public MyData GetDataById(int id)
{
    DAL myDAL = new DAL();
    return myDAL.GetDataById(id);
}

The class MyData looks like the following

public class MyData
{        
    public string Name;
    public Data[] DataItems;     
}

and the class Data,

public class Data
{
    public string key;
    public string value;
}

Now this worked fine for until we wanted to return a bit of complex types.

For an example, a DataTable, or perhaps something like a structure (or class) containing latitude, longitude and a value. So obviously, class Data cannot hold multiple values or a DataTable. (It contains two strings, key and value).

So what I actually want is the type to be Generic. So I changed it to…

public class MyData<T>
{        
    public string Name;
    public T[] DataItems;     
}

So I’ll be doing something like this inside the myDAL.GetDataById because what type of data is returned differs according to the type.

if (GetTypeOfId(id) == "NormalData")
{
   MyData<Data> result = new MyData<Data>();
}
else if (GetTypeOfId(id) == "Map")
{
   MyData<MapData> result = new MyData<MapData>();
}

But I need to specify a type for the method signature as well which unfortunately is found out ONLY at run time.

How do I handle such a situation ?

I feel like I am using Generics for something I shouldn’t be using it for.

Or how is usually a situation where the type is found out only at run time resolved?

UPDATE: The worst case scenario is having different web service calls for getting normal data and map data which I would like to avoid.

  • 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-23T00:53:08+00:00Added an answer on May 23, 2026 at 12:53 am

    The answer was pretty easy and stupid of me not to think of it before.
    I just created a parent class and made the Data and all the other required classes inherit from it.

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

Sidebar

Related Questions

I have a page based web method which works fine, using [WebMethod], i.e [WebMethod]
I have a web service method in which I create a particular type of
I have a method in my web service which returns a DataView, I have
If I have a web service method, e.g. [WebMethod] [XmlInclude(typeof(SportsCar)), XmlInclude(typeof(FamilyCar))] public Car[] GetCars()
When I call, the service's method, I have Web Service Exception happening which I
I have a Web Service with Just one Web Method that returns a boolean
I have now something like this: public class Service1 : System.Web.Services.WebService { [WebMethod] public
I have a web page with several jQuery ajax calls which fire asynchronously at
I'm working with a VB.Net page which calls a web method from JavaScript, this
I have a web service in which I am manipulating POST and GET methods

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.