Rhys Drury
Rhys Drury

Reputation: 315

WCF Web services and Windows Phone

Just a quick question as I'm struggling to get my Web Service working. Basically I followed a tutorial as I'm new to Windows Phone and Databases,

"http://studentguru.gr/b/dt008/archive/2010/12/02/querying-a-database-on-windows-phone-7-using-wcf.aspx"

However i'm using my own database, a .sdf file created in visual studio

I managed to create the service, the references and all the methods it said to make. However when I try to grab the data from the service at runtime it just returns

       Timesheet_System.Servicereference.TimeData
       Timesheet_System.Servicereference.TimeData
       Timesheet_System.Servicereference.TimeData
       Timesheet_System.Servicereference.TimeData

For all 4 of the items in the database.

Does anyone know a reason why? Thanks a lot. Code Below:

I have a data service in an asp.net site, and an ado.net data model, then i have a service reference in the phone app and 2 methods to call data This is the data service code in the asp.net application

namespace TimesheetDataSite
{
     [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode =     AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
    [OperationContract]
    public List<TimeData> DoWork()
    {
        // Add your operation implementation here
        using (TimeDataEntities2 entities = new TimeDataEntities2())
        {
            var alldata = from x in entities.TimeDatas select x;
            return alldata.ToList();
        }
    }

    // Add more operations here and mark them with [OperationContract]
}

}

the 2 methods in the phone app

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
        Service1Client client = new Service1Client();

        client.DoWorkCompleted +=
            new EventHandler<DoWorkCompletedEventArgs>(client_DoWorkCompleted);
        client.DoWorkAsync();
    }
    void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
    {
        if (e.Error == null)
        {

            listBox1.ItemsSource = e.Result;
        }
    }

}

Upvotes: 0

Views: 518

Answers (1)

Daniel Kelley
Daniel Kelley

Reputation: 7737

TimeData As per my comment, try the following:

void client_DoWorkCompleted(object sender, DoWorkCompletedEventArgs e)
{
    if (e.Error == null)
    {
        listBox1.DisplayMemberPath = "PropertyA";
        listBox1.ItemsSource = e.Result;
    }
}

Where PropertyA is the name of the property on TimeData that you want to display.

Like I said, I don't have Visual Studio available to test this but it should work.

Upvotes: 1

Related Questions