0

I was created this return from WCF and may i know how could i read the data specifically ??

[DataContract]
public class UserData
{
    [DataMember]
    public int userID { get; set; }

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

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

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

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

This is WCF side and returning from WCF, i want to read this from Window phone. may i know is there some example ? Thank you for reply

Update

The code in phone part where i want to use the data

        private Service1Client _serviceClient;
    public Login()
    {
        InitializeComponent();
        _serviceClient = new Service1Client();
        _serviceClient.LoginUserCompleted += new EventHandler<LoginUserCompletedEventArgs>(_serviceClient_LoginUserCompleted);

    }

    private void loginBtn_Click(object sender, RoutedEventArgs e)
    {
        _serviceClient.LoginUserAsync(txtEmail.Text, txtPassword.Password);
    }

    private void _serviceClient_LoginUserCompleted(object sender, LoginUserCompletedEventArgs e)
    {

        if (e.Error == null && e.Result != null)
        {
            (App.Current as App).MyUserID = 16;
            MessageBox.Show("Welcome " + e.Result + "!");
            //ContentPanel.Visibility = Visibility.Collapsed;
            //Data.Visibility = Visibility.Visible;
            //Testing.ItemsSource = e.Result;

Wondering how could i make this few line of code to read the data accordingly, make it into list or can be extract specific data and currently this few lines of codes giving me this answer ::

            WCFReference.UserData
        }
        else
        {
            MessageBox.Show(e.Error.InnerException.Message + " Couldn't Login, Please try again =D");
        }
    }
1myb
  • 3,536
  • 12
  • 53
  • 73
  • Did you create a web service? If so, you can simply add a service reference to the service and then the proxy that reads this type will be generated. – Emond May 13 '12 at 16:44

2 Answers2

1

If you are using the SOAP protocol you could either build an WSDL to describe the webservice or you could create the custom class right on the client based on your knowledge of the webservice.

If you are using the REST protocol (Which would be the best alternative for an WP7 Application) you have to create the class on the client based on your knowledge because there are no such thing as WSDL that can describe an REST webservice.

Here is an start for you.

public class UserData
{
    public int userID { get; set; }
    public string name { get; set; }
    public string email { get; set; }
    public string contact { get; set; }
    public string status { get; set; }
}

Now you just have to parse the response from the webservice request as an UserData class and whoala you are all set.

And as some people pointed out, you can use the webservice as an service reference if you prefer that but sometimes it just messes things up.

parek
  • 772
  • 1
  • 13
  • 41
0

You can consume exposed web services by creating service reference (proxy).

Check out following URLs

Adil
  • 3,248
  • 1
  • 22
  • 27