I want to create and consume a WCF Service in Silverlight. I have created a service that returns this model from a database:
namespace SilverlightWithWCFService.Web
{
[DataContract]
public class Customer
{
[DataMember]
public string CustomerName { get; set; }
[DataMember]
public string CompanyName { get; set; }
[DataMember]
public string ContactName { get; set; }
}
}
The service looks like this:
namespace SilverlightWithWCFService.Web
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SampleService
{
[OperationContract]
public List<Customer> CustomerList()
{
var custList = new List<Customer>();
// populate custList
return custList;
}
}
}
}
In my Silverlight application, I added a Service Reference. This method calls the service operation:
public Page()
{
InitializeComponent();
SampleServiceClient client = new SampleServiceClient();
client.CustomerListCompleted += new EventHandler<CustomerListCompletedEventArgs>(client_CustomerListCompleted);
client.CustomerListAsync();
}
void client_CustomerListCompleted(object sender, CustomerListCompletedEventArgs e)
{
CustomerGrid.ItemsSource = e.Result;
}
So my question is: I don't know how the Silverlight work with WCF. Do I have to serialize something on WCF side and deserialize the return value on client side? If so, what code is missing? (Where?)
UPDATE:
I think based on some online questions. Should I deserialize the returned e.Result
in the completed event code?