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");
        }
    }

登录.xaml.cs

我想从 Entity Framework 返回整个表,并允许我在 Window Phone 端一一处理。

我想我需要对 IService 端做一些修改,但我真的不知道怎么做,因为我是电话开发的新手并且习惯于 Linq to SQL。请您指导我如何为退货制作类似类型的东西,拜托。谢谢你。

更新

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

我将代码修改为WCF 自定义对象中所述的方式,但我无法反序列化它......我猜问题来自 WP 部分,我该如何反序列化结果

4

2 回答 2

1

您需要使用数据合同:

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

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

在服务中它看起来像这样:

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

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

于 2012-05-12T14:19:16.737 回答
1

您可以使用ref也可以使用自定义对象

于 2012-05-12T14:20:43.373 回答