views:

460

answers:

3

I'm passing an object to a WCF service and wasn't getting anything back. I checked the variable as it gets passed to the method that actually does the work and noticed that none of the values are set on the object at that point. Here's the object:

[DataContract]
public class Section {

    [DataMember]
    public long SectionID { get; set; }

    [DataMember]
    public string Title { get; set; }

    [DataMember]
    public string Text { get; set; }

    [DataMember]
    public int Order { get; set; }
}

Here's the service code for the method:

[OperationContract]
public List<Section> LoadAllSections(Section s) {
    return SectionRepository.Instance().LoadAll(s);
}

The code that actually calls this method is this and is located in a Silverlight XAML file:

SectionServiceClient proxy = new SectionServiceClient();
proxy.LoadAllSectionsCompleted += new EventHandler<LoadAllSectionsCompletedEventArgs>(proxy_LoadAllSectionsCompleted);
 Section s = new Section();
 s.SectionID = 4;
 proxy.LoadAllSectionsAsync(s);

When the code finally gets into the method LoadAllSections(Section s), the parameter's SectionID is not set. I stepped through the code and when it goes into the generated code that returns an IAsyncResult object, the object's properties are set. But when it actually calls the method, LoadAllSections, the parameter received is completely blank. Is there something I have to set to make the proeprty stick between method calls?

A: 

Works just fine for me - could it be a silly typo??

In your OperationContract, you define LoadAllSections but in your client code, you attach an event handler to the proxy.GetAllSectionsCompleted event - maybe that's just the wrong handler? Shouldn't it be proxy.LoadAllSectionsCompleted ??

Marc

marc_s
Does it matter if I'm calling this code from a Silverlight XAML file? I still can't get the values to stick after coming back from the result. Sorry about the typo above, I'll fix it.
Josh
Certainly important to know about Silverlight!
marc_s
A: 

This seems odd, but it's what happens. I had another method on the service that returned a DataTable. Whenever a method tries to return a DataTable, the parameters passed in lose their values. Take out the method, and everything works. Odd.

Josh
very odd indeed......
marc_s
That sounds like a mismatch between client and service. Rebuild the service; start the service; do an Update Service Reference in the client app (make sure URL is pointing to started, rebuilt service); rebuild client and try again.
John Saunders
A: 

Is datatable serializable?

Nilotpal Das