我有一个 Web 服务,它返回一个自定义类(用户)的对象:
网络服务代码
public class User
{
public string login { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
}
[WebMethod]
public User GetUserInfo(int userID)
{
ITDashboardDataContext db = new ITDashboardDataContext();
User usr = (from u in db.tl_sb_users
where u.userID == userID
select new User
{
firstName = u.firstName,
lastName = u.lastName,
email = GetUserEmail(userID),
login = u.login
}).FirstOrDefault();
return usr;
}
当我从另一个应用程序调用 Web 服务时,我想将结果转换为用户对象(我也在这个应用程序中重新定义了用户类):
调用应用程序代码
public class User
{
public string login { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
}
我试图用这个带回一个用户对象:
RolloutWriter.RolloutWriter rw = new RolloutWriter.RolloutWriter();
rw.Credentials = new NetworkCredential("myuser", "mypassword", "mydomain");
var vu = rw.GetUserInfo(userID);
User u = (from v in vu
select new User {
email = vu.email,
firstName = vu.firstName,
lastName = vu.lastName,
login = vu.login
}).FirstOrDefault();
这不起作用 - 它告诉我:
Could not find an implementation of the query pattern for source type 'amstaffsite.RolloutWriter.User'. 'Select' not found.
如何取回用户对象?