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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:21:36+00:00 2026-05-26T07:21:36+00:00

I have set up a WCF Web Api service, and everything was working fine,

  • 0

I have set up a WCF Web Api service, and everything was working fine, until I started using DTOs to expose data.

Previously I had on the WCF Service my model object which was called Game.cs:

public class Game
{
    public int Id { get; set; }
    public string Description { get; set; }
    public string Developer { get; set; }
    public Genre Genre { get; set; }
    public string Name { get; set; }
    public decimal? Price { get; set; }
    public string Publisher { get; set; }
    public Rating Rating { get; set; }
    public DateTime? ReleaseDate { get; set; }
}

The get method in the service looked like this:

public IQueryable<Game> GetGames()
    {
        var db = new XBoxGames();
        var games = db
            .Games
            .Include("Genre")
            .Include("Rating")
            .OrderBy(g => g.Id)
            .ToList()
            .AsQueryable();
        return games;
    }

In the MVC 3 client application I had a controller action that requested all my games: (I’m using restsharp)

public ActionResult Index()
    {
        var request = new RestRequest(Method.GET);
        var restClient = new RestClient();
        restClient.BaseUrl = "http://localhost:4778";
        request.Resource = "games";
        var response = restClient.Execute<List<Game>>(request);
        var games = response.Data;
        return View(games);
    }

and the client model:

public class Game
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Developer { get; set; }
    public int GenreId { get; set; }
}

After I started using DTOs, the client was not getting any information about any game, eventhough the service was returning the info. The get method in the service changed a little bit, now instead of returning my model, I am returning a DTO object which has the information I actually want to expose over the API:

[WebGet(UriTemplate = "")]
    public IQueryable<GameDTO> GetGames()
    {
        var db = new XBoxGames();
        var games = db
            .Games
            .Include("Genre")
            .Include("Rating")
            .OrderBy(g => g.Id)
            .ToList();
        var gamesDTO = Mapper.Map<List<Game>, List<GameDTO>>(games);
        return gamesDTO.AsQueryable();
    }

The DTO object has the following structure:

public class GameDTO
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Developer { get; set; }
    public string GenreName { get; set; }
}

The xml returned by the service looks like this:

<ArrayOfGameDTO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <GameDTO>
    <Id>3</Id>
    <Name>Jade Empire™</Name>
    <Description>
     ...
    </Description>
    <Developer>BioWare Corp.eeeddd</Developer>
 </GameDTO>
 <GameDTO
  .
  .
  . 
 </GameDTO>
</ArrayOfGameDTO>

I noticed that the xml root tag has now changed from ArrayOfGame to ArrayOfGameDTO, and that seems to be a problem for restsharp, since in my client application my model for games is called Game.cs, so in order to get the client application to work my client model needs to have tha same name as de DTO object in the service (GameDTO). I found this solution a little odd, so my question: is there a way to get things working without having DTOs and client models named the same?

Any help would be appreciate it… 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-26T07:21:37+00:00Added an answer on May 26, 2026 at 7:21 am

    You can try to do the following

    namespace MyDTONamespace {
      public class Game { ... }
    }
    

    and in your service:

    using DTO = MyDTONamespace;
    
    namespace MyServiceNamespace {
      public class MyService {
        [WebGet(UriTemplate = "")]
        public IQueryable<DTO.Game> GetGames() {
          var db = new XBoxGames();
          var games = db
              .Games
              .Include("Genre")
              .Include("Rating")
              .OrderBy(g => g.Id)
              .ToList();
          var gamesDTO = Mapper.Map<List<Game>, List<DTO.Game>>(games);
          return gamesDTO.AsQueryable();
        }
      }
    }
    

    I’m curious to what this serializes, but I think this could work.

    EDIT: I thought you were renaming them on the client to DTO.

    The other option that I can think of is to make your DTOs serialization-aware. I assume you’re using the DataContractSerializer (WCF default) so you can use the Name property of the DataContract attribute, see here.

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

Sidebar

Related Questions

I am using a WCF authentication service I set up with a web application.
I have a set of services hosted with WCF Web Api, what I need
Currently I have a web service (WCF) that exposes methods that are set to
I have a WCF web service that used to work fine. Somewhere down the
I have installed WCF Web API Preview 5 using NuGet Visual Studio extension (WebApi.All).
I am currently using the WCF Web API and it is working great with
I have a set of WCF web services connected to dynamically by a desktop
I have a self-hosted WCF service with the InstanceContextMode set to PerSession. How can
I'm developing a web service using NHibernate, WCF and Oracle 11g R1. The web
I have converted my web service to wcf service which has some datacontracts. As

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.