2012-05-12 71 views
0

我使用WCF从实体框架中查询这个数据,我想使用手机客户端的数据,我可以知道如何从WCF函数查询多个数据类型?返回多个数据类型

[OperationContract] 
string LoginUser(string email, string password); 

IService.cs

 public string LoginUser(string email, string password) 
    { 
     string query = @"SELECT VALUE tblUser FROM MyEntities.tblUsers AS tblUser WHERE tblUser.email = @email AND tblUser.password = @password"; 
     ObjectParameter[] parameters = new ObjectParameter[2]; 
     parameters[0] = new ObjectParameter("email", email); 
     parameters[1] = new ObjectParameter("password", password); 

     using (var context = new SteamKingEntities()) 
     { 
      ObjectQuery<string> results = context.CreateQuery<string>(query, parameters); 
      foreach (string result in results) 
      { 
       if (result != null) 
       { 
        return result; 
       } 
      } 
     } 
     return null; 
    } 

IService.svc.cs

 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) 
     { 
      MessageBox.Show("Welcome " + e.Result + "!"); 
     } 
     else 
     { 
      MessageBox.Show(e.Error.Message + " Couldn't Login, Please try again =D"); 
     } 
    } 

Login.xaml.cs

我想从实体框架返回整个表格,并允许我在Window Phone一边逐一处理。

我想我需要做一些修改的IService方面,但我真的不知道如何,因为我是新手机开发和习惯Linq到SQL。你能指导我如何制作类似的回报,请。谢谢。

更新

的错误,我得到There was an error while trying to deserialize parameter http://tempuri.org/:LoginUserResult. Please see InnerException for more details.

我修改的代码到WCF Custom Object陈述的方式,但我不能反序列化。我想这个问题从WP的部分来了, 我怎么反序列化结果

+0

我不明白你的类型w ant返回 – ivowiblo

+0

这是我得到的错误:从物化的'WCFServiceWebRole1.tblUser'类型到'System.String'类型的指定强制转换无效。 – 1myb

+0

什么在InnerException?你刷新了服务参考吗? – gabba

回答

1

您可以使用ref或者你可以使用custom-objects

+0

我被编辑为引用的方式,但是我可以知道如何解决新问题吗?Thx回复 – 1myb

+0

现在我不知道我该怎么处理电话部分,让我的手机知道要读取我想要的数据类型,并通过数据将数据行反序列化为特定数据... – 1myb

1

您需要使用数据契约:

[DataContract] 
    public class ReturnType 
    { 
     [DataMember] 
     public string Name { get; set; } 

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

服务它应该是这样的:

[OperationContract] 
    Entities.ReturnType[] SelectTopUser(int countOfTop); 

返回类型可以是实体框架型

+0

我创建了一个名为UserData的类并创建数据合同里面,然后把我的操作合同改成[OperationContract] UserData LoginUser(string email,string password); 但仍不能使... – 1myb

+0

还需要刷新客户端代码(电话端)的服务参考。你遇到了什么困难? – gabba

+0

现在我不知道我该怎么处理电话部分,通过让我的手机知道要读取我想要的数据类型,并通过数据将数据行反序列化为特定数据... – 1myb