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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:45:31+00:00 2026-05-10T21:45:31+00:00

I am trying to send an anonymous object over a web service. Is there

  • 0

I am trying to send an anonymous object over a web service. Is there anyway I can do this without manually creating a class and casting it to that class? Currently its throwing an exception saying Anonymous object could not be serialized.

// Some code has been removed here to simplify the example. [WebMethod(EnableSession = true)] public Response GetPatientList() {     var patientList = from patient in ((User)Session['user']).Practice.Patients                       select new {                           patientID = patient.PatientID,                           status = patient.Active ? 'Active' : 'Inactive',                           patientIdentifier = patient.PatientIdentifier,                           physician = (patient.Physician.FirstName + ' ' + patient.Physician.LastName).Trim(),                           lastModified = patient.Visits.Max(v => v.VisitDate)                       };     return patientList; } 

Thanks in advance.

Edit: Here is an example of what I mean by manually creating a class to return and fill it with the anonymous object…

public class Result {     public bool success;     public bool loggedIn;     public string message; }  public class PracticeInfoResult : Result {     public string practiceName;     public string address;     public string city;     public string state;     public string zipCode;     public string phone;     public string fax; } 
  • 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. 2026-05-10T21:45:32+00:00Added an answer on May 10, 2026 at 9:45 pm

    Anonymous type are meant to be used for simple projections of very loosely coupled data, used only within a method. If it makes sense for a web method to return data of a type, it really should be decently encapsulated. In other words, even if you can find a way to return an instance of an anonymous type from a web method, I strongly suggest you don’t do it.

    I would personally not create the classes with public fields either – use automatically implemented properties instead, so you can safely add more behaviour later if you need to.

    Note that after you’ve created the ‘proper’ type, your query expression only needs to change very, very slightly – just add the name of the type between new and { to use an object initializer.

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

Sidebar

Related Questions

I suspect this isn't possible as the anonymous inner class is private. Can I
I am trying to send an anonymous type with RenderPartial but this method only
Trying to send 3rd party scripts over an SSL or SPDY connection is a
I'm trying to send an XMLHttpRequest object to my Rails server but the headers
I'm trying to put together a class to handle Ipc between processes using anonymous
Im trying to send a Docx file via this form that I made, the
Am trying to send a mail to recipient from iPhone app without user's interaction.
Im trying to send a mail from a asp.net script, but im getting this
Im trying to send multiple data items over a tcp socket from an android
Im trying to send images over HTTP using HttpListener but some images come from

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.