0

I have a WCF service, and I want to return a List<ThePassenger> to the client. In my interface section I have declared a function that returns List<ThePassenger> and implemented it.

[OperationContract]
List<ThePassenger> GetPassengers();

And this is ThePassenger struct:

[DataContract]
public struct ThePassenger
{
    [DataMember]
    public string firstname;
    [DataMember]
    public string lastname;
    [DataMember]
    public string passport;
    [DataMember]
    public string flight;
    [DataMember]
    public string ticket;
    [DataMember]
    public string meal;
    [DataMember]
    public string baggage;
    [DataMember]
    public string bookingkey;
};

In client's service reference settings I set my collection to Generic.List, but when I run this code on client:

MyServiceClient client = new MyServiceClient();
client.GetPassengers();

I get System.ObjectDisposedException: cannot access a disposed object.

What am I doing wrong?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • For one, please change your fields into proper Properties. And use a proper naming convention. Also, post the server side code and the Stacktrace. – Federico Berasategui Feb 26 '14 at 20:56
  • 3
    Side-note: mutable structs are [Considered Harmful](http://stackoverflow.com/questions/441309/why-are-mutable-structs-evil). – Blorgbeard Feb 26 '14 at 20:57
  • We need a full stack trace for this. The problem seems to be inside client.GetPassengers(); call, but you didn't provided the code of this method – Oscar Feb 26 '14 at 20:57
  • Can you show your implementation for `GetPassengers()`? – Mike Christensen Feb 26 '14 at 20:57
  • SIDE NOTE: Since, COLLECTION is very much specific to .Net, WCF does not expose it to the metadata of the service. WCF provides dedicated marshaling rules for collection. Collection will be exposed as array in service metadata... Ergo use [] instead of IEnumerable or List – Petar Vučetin Feb 26 '14 at 22:42

1 Answers1

-1

looks like client proxy object is getting disposed or not initialized properly, try below mentioned code.

MyServiceClient client = null;
using(clinet = new MyServiceClient())
{
    client.GetPassengers();
}
Abhinay
  • 338
  • 1
  • 7
  • 22