在DataService.cs中,有方法:
public IQueryable<TabUser> GetTabUser()
{
return this.ObjectContext.TabUser;
}
[Invoke]
public int GetTabUserCount(string userName)
{
var result = from a in ObjectContext.TabUser
where a.Name.Contains(userName)
select a.ID;
return int.Parse(result.Count().ToString());
}
在silverlight页面的调用代码:
public void SelectTabUser()
{
dc.Load(dc.GetTabUser(), OnSelectTabUser, null);
}
public void GetUserPageCount(string UserName)
{
dc.GetUserPageCount(UserName,OnGetUserPageCount, null);
}
private void OnSelectTabUser(LoadOperation<TabUser> lop)
{
if (lop.HasError)
{
MessageBox.Show(string.Format("错误提示: {0}", lop.Error.Message));
lop.MarkErrorAsHandled();
}
else
{
TabUser = lop.Entities;
}
}
private void OnGetUserPageCount(InvokeOperation<int> invOp)
{
if (invOp.HasError)
{
MessageBox.Show(string.Format("错误提示: {0}", invOp.Error.Message));
invOp.MarkErrorAsHandled();
}
else
{
int pageCount = invOp.Value;
}
}
调用SelectTabUser方法的时候放回的数据是正确的,但是调用GetUserPageCount方法的时候,invOp.Error.Message提示Invoke operation 'GetUserPageCount' fail。请高手指点究竟哪里代码出现问题了,帮忙解决此问题!!
以前遇到过,好像是方法名字的问题,换个名字试试
WCF RIA Service有自己的一些约定,有时一些名字在sl的生成代码中处理不对
应该是你dataService里面的方法的问题