Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从wcf数据服务返回单个实体_Wcf_Wcf Data Services - Fatal编程技术网

从wcf数据服务返回单个实体

从wcf数据服务返回单个实体,wcf,wcf-data-services,Wcf,Wcf Data Services,我只是想知道如何从wcf数据服务返回单个实体 我想提供一个方法e公共用户登录(字符串用户名、字符串密码)并将loggedin用户返回到用户界面 谢谢 安迪,我想这会对你有帮助 我假设用户是您的实体表 public User Login(string username,string password) { Entity obj = new Entity(); User objUser = (from U in obj.User where U.username = username a

我只是想知道如何从wcf数据服务返回单个实体

我想提供一个方法e
公共用户登录(字符串用户名、字符串密码)
并将loggedin用户返回到用户界面

谢谢


安迪,我想这会对你有帮助

我假设用户是您的实体表

public User Login(string username,string password)
{
   Entity obj = new Entity();
   User objUser = (from U in obj.User where U.username = username and U.password = password Select U).Single();
   return objUser;
}

这对我来说很好,我希望它能帮助你。

老问题已经很老了,但你需要定义一个:

但是,
用户名
密码
通过URI以明文形式传递。更好的选择是从HTTP请求的
授权
头中提取
用户名
密码
数据,通过有线(SSL)加密请求。一个简单的例子是为数据服务定义一个构造函数,并在其中附加到
ProcessingRequest
事件:

public MyDataService() {
    this.ProcessingPipeline.ProcessingRequest += (o, e) => { 
        // 
        // Do stuff with e.OperationContext.RequestHeaders["Authorization"]
        // storing the result into an instance property
        //
    };
}

使用引用
用户名
密码
的授权属性的
用户GetCurrentUser()
服务操作,而不是接受它们作为
获取
查询字符串参数。

似乎是WCF的常见任务。你试过做一个原型吗?你真的有代码和我们分享吗?否则你的帖子就没有内容了。不,这不是一个常见的任务。事实上,这在数据服务中是不可能的。您忘了提到写入
SingleResult
声明的文件是什么。
public MyDataService() {
    this.ProcessingPipeline.ProcessingRequest += (o, e) => { 
        // 
        // Do stuff with e.OperationContext.RequestHeaders["Authorization"]
        // storing the result into an instance property
        //
    };
}