Hi i’m working on an app that gets data from DB using WCF Service. But when i want to show result on the phone it show me error in VS. I’m Converting in WCF from MachineEntity to Machine then I’m sending it to client app.
Here is the error, referring to e.Result:
Cannot implicitly convert type ‘WP7App.WCFService.Machine’ to ‘System.Collections.IEnumerable’. An explicit conversion exists (are you missing a cast?)
public FoundProduct(int s)
{
InitializeComponent();
Service1Client proxy = new Service1Client();
proxy.GetMachineCompleted += new
EventHandler<GetMachineCompletedEventArgs>(proxy_GetMachineCompleted);
proxy.GetMachineAsync(s);
}
void proxy_GetMachineCompleted(object sender, GetMachineCompletedEventArgs e)
{
listBox1.ItemsSource = e.Result;
}
Like the error message says, the
ItemsSourceproperty of theListBoxexpects an object implementing the interfaceIEnumerable. That is, most of the time, a collection of elements.If
Machineis supposed to be a collection of objects, then you’ll have to understand why it doesn’t implementIEnumerable(there isn’t enough context information here to figure it out).However, if
Machineis a single object that you want to assign to yourListBox(sounds weird, but…), you can wrap it in a collection: