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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:39:10+00:00 2026-05-25T09:39:10+00:00

OK… I’ve looked on the web and found two possible solutions to my issue

  • 0

OK… I’ve looked on the web and found two possible solutions to my issue of not being able to return an IEnumerable type in a .Net 4.0 WCF service.

See below link. This is exactly what I’m getting when I am executing the WCF Test Client tool and trying to invoke a method.

https://connect.microsoft.com/wcf/feedback/details/336696/ienumerable-t-serialization-bug

Mind you, to be sure there is nothing wrong with my web service, I am able to return a type of this object for a single record, just not an IEnumerable.

Both solutions that I have tried, shown below do not work for me. I get the same error. This is driving me crazy. I know what the issue is, followed steps to circumvent the issue, but I am still getting the same error.

How can I resolve this?

This is the first solution I tried: Note that I even tried removing the “ToList” and “ToArray” on the last statement in each of the methods because it’s implied already.

Interface

[OperationContract]
        IList<Priority> GetPriorities();

Method

public IList<Priority> GetPriorities()
        {
            YeagerTechEntities DbContext = new YeagerTechEntities();

            IList<Priority> priority = DbContext.Priorities.Where(p => p.PriorityID > 0).ToList();

            CloseConnection(DbContext);

            return priority.ToList();
        }

This is the second solution I tried:

Interface

[OperationContract]
        Priority[] GetPriorities();

Method

public Priority[] GetPriorities()

        {
            YeagerTechEntities DbContext = new YeagerTechEntities();

            Priority[] priority = DbContext.Priorities.Where(p => p.PriorityID > 0).ToArray();

            CloseConnection(DbContext);

            return priority.ToArray();
        }

Here it is with a List instead of an IList which still doesn’t work.

Interface

[OperationContract]
        List<Priority> GetPriorities();

Method

public List<Priority> GetPriorities()
        {
            YeagerTechEntities DbContext = new YeagerTechEntities();

            List<Priority> priority = DbContext.Priorities.Where(p => p.PriorityID > 0).ToList();

            CloseConnection(DbContext);

            return priority.ToList();
        }

Notice that the below method works fine when retrieving just one object instead of a list.

[OperationContract]
        Priority GetPriorityID(Int16 priorityid);



public Priority GetPriorityID(Int16 priorityid)
        {
            YeagerTechEntities DbContext = new YeagerTechEntities();

            Priority priority = null;

            var priorityEntity = (from p in DbContext.Priorities
                                  where p.PriorityID == priorityid
                                  select p).FirstOrDefault();

            if (priorityEntity != null)
            {
                priority = new Priority();
                priority.PriorityID = priorityEntity.PriorityID;
                priority.Description = priorityEntity.Description;
                CloseConnection(DbContext);
            }
            else
            {
                CloseConnection(DbContext);
                throw new Exception("Priority " + priorityid + " not found!");
            }

            return priority;
        }

The entire error msg from the wcf test client for the first method in this post is as follows. What is the resolution in order to be able to return a list of objects?

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

An error occurred while receiving the HTTP response to http://localhost:8732/Design_Time_Addresses/YeagerTechWcfService/YeagerTechWcfService/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ClientReliableChannelBinder1.RequestClientReliableChannelBinder1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder
1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at IYeagerTechWcfService.GetPriorities()
at YeagerTechWcfServiceClient.GetPriorities()

Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

Inner Exception:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

I modified my classes (see below), but am still getting the same exact error.

Surely, there must be someone who has tried this before where they get an object back from Entity Framework and want to pass it back as an IEnumerable. I’m very frustrated with this. Please help me out…

Based on my previous post, my classes are exactly the same with the following changes. I tried two methodologies.

Please refer to the first and second scenarios separately.

First scenario for Interface

I tried using just the Customer class and then an IEnumerable declaration of it.

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using YeagerTechModel;

namespace YeagerTechWcfService
{
//[ServiceKnownType(typeof(YeagerTechModel.Customer))]
 [ServiceKnownType(typeof(IEnumerable<YeagerTechModel.Customer>))]
 [ServiceContract]
 public interface IYeagerTechWcfService
 {

 [OperationContract]
IEnumerable<Customer> GetCustomers();

 [OperationContract]
 Customer GetCustomerID(Int16 customerid);

It resides in my YeagerTechModel project in the same solution referenced by my web service (the other project in the same solution).

First scenario for Customer object

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace YeagerTechModel
{
[Serializable]
[DataContract]
 public partial class Customer
 {
 public Customer()
 {
 this.Projects = new HashSet<Project>();
 }

 [DataMember]
 public short CustomerID { get; set; }

 [Required]
 [StringLength(50)]
 [DataType(DataType.EmailAddress)]
 [DataMember]
 public string Email { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string Company { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string FirstName { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string LastName { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string Address1 { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string Address2 { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string City { get; set; }

 [StringLength(2)]
 [DataType(DataType.Text)]
 [DataMember]
 public string State { get; set; }

 [StringLength(10)]
 [DataType(DataType.Text)]
 [RegularExpression(@"^\d{5}(-\d{4})?$")]
 [DataMember]
 public string Zip { get; set; }

 [StringLength(12)]
 [DataType(DataType.PhoneNumber)]
 public string HomePhone { get; set; }

 [StringLength(12)]
 [DataType(DataType.PhoneNumber)]
 [DataMember]
 public string CellPhone { get; set; }

 [StringLength(100)]
 [DataType(DataType.Url)]
 [DataMember]
 public string Website { get; set; }

 [StringLength(50)]
 [DataType(DataType.EmailAddress)]
 [DataMember]
 public string IMAddress { get; set; }

 [DataMember]
 public System.DateTime CreatedDate { get; set; }

 [DataMember]
 public Nullable<System.DateTime> UpdatedDate { get; set; }

 public virtual ICollection<Project> Projects { get; set; }

 }

Second scenario for interface:

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using YeagerTechModel;

namespace YeagerTechWcfService
{
 [ServiceContract]
 public interface IYeagerTechWcfService
 {

 [OperationContract]
IEnumerable<Customer> GetCustomers();

 [OperationContract]
 Customer GetCustomerID(Int16 customerid);

Second scenario for Customer object

I have tried using just the Customer class and then an IEnumerable declaration of it at the bottom of this class.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace YeagerTechModel
{
 [KnownTypeAttribute("KnownTypes")]
 [Serializable]
 [DataContract]
 public partial class Customer
 {
 public Customer()
 {
 this.Projects = new HashSet<Project>();
 }

 [DataMember]
 public short CustomerID { get; set; }

 [Required]
 [StringLength(50)]
 [DataType(DataType.EmailAddress)]
 [DataMember]
 public string Email { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string Company { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string FirstName { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string LastName { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string Address1 { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string Address2 { get; set; }

 [StringLength(50)]
 [DataType(DataType.Text)]
 [DataMember]
 public string City { get; set; }

 [StringLength(2)]
 [DataType(DataType.Text)]
 [DataMember]
 public string State { get; set; }

 [StringLength(10)]
 [DataType(DataType.Text)]
 [RegularExpression(@"^\d{5}(-\d{4})?$")]
 [DataMember]
 public string Zip { get; set; }

 [StringLength(12)]
 [DataType(DataType.PhoneNumber)]
 public string HomePhone { get; set; }

 [StringLength(12)]
 [DataType(DataType.PhoneNumber)]
 [DataMember]
 public string CellPhone { get; set; }

 [StringLength(100)]
 [DataType(DataType.Url)]
 [DataMember]
 public string Website { get; set; }

 [StringLength(50)]
 [DataType(DataType.EmailAddress)]
 [DataMember]
 public string IMAddress { get; set; }

 [DataMember]
 public System.DateTime CreatedDate { get; set; }

 [DataMember]
 public Nullable<System.DateTime> UpdatedDate { get; set; }

 public virtual ICollection<Project> Projects { get; set; }

 static Type[] KnownTypes()
 {
return new Type[] { typeof(IEnumerable<Customer>) };
 }

 }

I tried:

return customer;
return customer.ToList();
return customer.ToArray();


public IEnumerable<Customer> GetCustomers()
 {
 YeagerTechEntities DbContext = new YeagerTechEntities();

 IEnumerable<Customer> customer = DbContext.Customers.Where(p => p.CustomerID > 0);

 CloseConnection(DbContext);

return customer;
 }

The problem seems to be a serialization issue when trying to pass back the Customer object which is part of an Entity Framework model. There has to be a documented way of passing back an object of this type which is derived from an Entity Framework model.

Where is it????

Here is the latest of what I tried and am still getting the same exact error….

namespace YeagerTechWcfService
{
    [ServiceContract]
    public interface IYeagerTechWcfService
    {
        [OperationContract]
        List<Customer> GetCustomers();



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace YeagerTechModel
{
    [Serializable]
    [DataContract]
    public partial class Customer
    {
        public Customer()
        {
            this.Projects = new HashSet<Project>();
        }

        [DataMember]
        public short CustomerID { get; set; }

        [Required]
        [StringLength(50)]
        [DataType(DataType.EmailAddress)]
        [DataMember]
        public string Email { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        [DataMember]
        public string Company { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        [DataMember]
        public string FirstName { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        [DataMember]
        public string LastName { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        [DataMember]
        public string Address1 { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        [DataMember]
        public string Address2 { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        [DataMember]
        public string City { get; set; }

        [StringLength(2)]
        [DataType(DataType.Text)]
        [DataMember]
        public string State { get; set; }

        [StringLength(10)]
        [DataType(DataType.Text)]
        [RegularExpression(@"^\d{5}(-\d{4})?$")]
        [DataMember]
        public string Zip { get; set; }

        [StringLength(12)]
        [DataType(DataType.PhoneNumber)]
        public string HomePhone { get; set; }

        [StringLength(12)]
        [DataType(DataType.PhoneNumber)]
        [DataMember]
        public string CellPhone { get; set; }

        [StringLength(100)]
        [DataType(DataType.Url)]
        [DataMember]
        public string Website { get; set; }

        [StringLength(50)]
        [DataType(DataType.EmailAddress)]
        [DataMember]
        public string IMAddress { get; set; }

        [DataMember]
        public System.DateTime CreatedDate { get; set; }

        [DataMember]
        public Nullable<System.DateTime> UpdatedDate { get; set; }

        public virtual ICollection<Project> Projects { get; set; }
    }


public List<Customer> GetCustomers()
        {
            YeagerTechEntities DbContext = new YeagerTechEntities();

            List<Customer> customer = DbContext.Customers.Where(p => p.CustomerID > 0).ToList();

            return customer.ToList();
        }
  • 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-25T09:39:10+00:00Added an answer on May 25, 2026 at 9:39 am

    The answer was as simple as setting a property to false before making my EF call to the database.
    DbContext.Configuration.ProxyCreationEnabled = false;
    EF automatically generates a proxy class. Dynamic Proxies – They don’t play nice over the wire – Turn these off (ContextOptions.ProxyCreationEnabled == false).

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

Sidebar

Related Questions

CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
English is not my native language. I need a software to spellcheck and correct
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I have a PDB file. Now it has two parts separated by TER. Before
what about this one: I want to format the currentTime displayed by a videoPlayer
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I want to sign a message according to the RSA-SHA1 Signature Method in OAuth
I have been making a wordpress template. i got stuck at some place... the
When I use the list function: el_nino_1974_2000_all <- list() for (k in seq_along(el_nino_start_month)){ el_nino_1974_2000_all[[k]]

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.