I have written a simple WebMethod in a back end webservice. I am using this as a service reference in both a WPF application and a Silverlight application.
The method returns a List<string> called userList. This works fine in the WPF application, where I reference the Service1SoapClient as ‘client’. There fore call the method by –
client.userlist(); //this is the case in WPF app
However in Silverlight the only option is
client.userListAsync(); //Silverlight
This works fine in WPF and brings back the desired list, however Silverlight brings back the error –
Error 11 Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>'
Also in relation to this, in the WPF app I am appending text withing a richTextBox with the userList, which works, however in Silverlight richTextBox1.AppendText is not a valid option.
Where am I going wrong in the Silverlight App?
All web service calls in Silverlight are asynchronous, meaning that you can’t make your application block execution while it waits for the result to come back. Instead you tell Silverlight what to do when it gets the result and let it carry on with its own business until then.
Your Silverlight app’s web service client requires you to pass it an event handler which will take the web method’s return value as a xxxCompletedEventArgs parameter, where “xxx” is the name of your web method.
This page: http://msdn.microsoft.com/en-us/library/cc197937(v=vs.95).aspx tells you how to set up your event handler and use it to process the output of a web service call.
From the page: