WCF服务-来自客户端的呼叫 [英] WCF service - Call from client

查看:110
本文介绍了WCF服务-来自客户端的呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是WCF的新手.我想创建一个连接到WCF服务的简单桌面登录应用程序[该服务用于连接到SQL Server,并使用Linq to Entities获取需要的数据],并验证是否存在该用户.我有以下事情.

1)使用1个名为GetUserDetails(sting userName)的函数创建了WCF服务.

Hello,

I am new to WCF. I wanted to created a simple desktop login application that connects to WCF service [Service is used to connect to SQL server and get requires data using Linq to Entities] and verifies wheather user existed or not. I have following the following things.

1) Created a WCF service with 1 function Named GetUserDetails(sting userName)

public List<AuthenticationModel> GetUserDetails(string UserName)
        {

            RiverEntity RiverEntity = new RiverEntity();

            List<AuthenticationModel> users = (from p in RiverEntity.Users
                                               where p.UserName == UserName
                                               select new AuthenticationModel
                                               {
                                                   UID = (int) p.UID,
                                                   ULastName = p.ULName,
                                                   UFirstName = p.UFName,
                                                   UMiddleName = p.UMName,
                                                   UserDMID = p.UserDMID,
                                                   UserName = p.UserName,
                                                   Password = p.Pass,
                                                   Active = (bool) p.Active,
                                                   Role = (int) p.Role,
                                                   Practices = p.Practices,
                                                   RegisteredEmail= p.RegisteredEmail,
                                                   DynaIP = p.DynaIP,
                                                   LoggedInStatus = p.loggedInStatus,
                                                   AppID = p.AppID,
                                                   ResetPass = (bool) p.ResetPass
                                               }).ToList<AuthenticationModel>();

            return users;
        }




2)为我的数据库的实体添加了Linq

3)创建WPF应用程序,并将服务引用添加到我的WPF客户端应用程序.

通过使用WCF测试客户端,我可以从数据库中获取用户详细信息.

现在我想从WPF做到这一点.谁能解释我如何创建代理,调用上述函数并将检索到的值存储到WPF最终属性中.

提前谢谢.

chowdary.




2) Added Linq to Entities for my DB

3) Created WPF application and added the service reference to my WPF client application.

By Using WCF test client i am able to get user details from Data base.

Now i wanted to do this from WPF. Can anybody explain me how to create proxy, call the above mentioned function and stores the retrived values into the WPF end properties.

Thanks in advance.

chowdary.

推荐答案

非常简单.
由于已经添加了服务引用,因此您会看到引用的名称,例如ServiceReference1(默认情况下).
然后要使用调用方法,您需要创建客户端对象,即
Its pretty easy.
Since you have added service reference, you see the name of the reference, like ServiceReference1 (by default).
Then to use call the method, you need to create client object, i.e.
ServiceReference1Client clientObj = new ServiceReference1Client();


然后


and then

var result = clientObj.GetUserDetails("your parameter");


现在,您可以将其直接绑定到接受该集合的任何对象.


Now, you can directly bind it to any object which takes the collection.


ThreeServiceRef.YourClass obj = new ThreeServiceRef.YourClass();
var result = clientObj.GetUserDetails("your parameter");


这篇关于WCF服务-来自客户端的呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆