Asp.net 调用WCF数据服务布尔方法
我正在尝试从客户端接收来自WCF方法的答案。当我尝试执行void方法时,它们工作得很好。例如:Asp.net 调用WCF数据服务布尔方法,asp.net,wcf,wcf-data-services,odata,Asp.net,Wcf,Wcf Data Services,Odata,我正在尝试从客户端接收来自WCF方法的答案。当我尝试执行void方法时,它们工作得很好。例如: Uri u = new Uri(string.Format(LogIn.ctx.BaseUri + "/CreateRole?name='{0}'", TextBox1.Text), UriKind.RelativeOrAbsolute); LogIn.ctx.Execute(u, "GET"); 现在我想调用一个返回布尔值的方法,将使用这个值。下面是我要调用并接收其返回值的方法: [WebGet
Uri u = new Uri(string.Format(LogIn.ctx.BaseUri + "/CreateRole?name='{0}'",
TextBox1.Text), UriKind.RelativeOrAbsolute);
LogIn.ctx.Execute(u, "GET");
现在我想调用一个返回布尔值的方法,将使用这个值。下面是我要调用并接收其返回值的方法:
[WebGet]
public bool Controler(string role, string user)
{
if (Roles.IsUserInRole(user, role))
{
return true;
}
else
{
return false;
}
}
请尝试以下操作,而不是
LogIn.ctx.Execute(u,“GET”)
:
IEnumerable<bool> result = LogIn.ctx.Execute<bool>(u);
bool answer = result.Single();
IEnumerable result=LogIn.ctx.Execute(u);
bool answer=result.Single();
第二种方法不起作用吗?如果没有,您能否对您的答案添加一些解释,说明发生了哪些不正确的行为?我猜客户端没有发回数据?我试过了,但它抛出了DataServiceQueryException,当我检查异常的详细信息时,有一个“空引用对象引用未设置为对象的实例”,看起来调用没有收到任何结果。。我已经更改了服务中的方法,并进行了一个简单的测试以返回false,但没有办法!它起作用了,我不得不再次重建/更新服务引用。谢谢