WCFDataService Unable to convert
I have created a WCFDataService, and have a custom webget methord for user validation, using it from wpf application.
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("ValidateUser", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
config开发者_如何学编程.UseVerboseErrors = true;
}
[WebGet]
public bool ValidateUser(string UserName, string Password)
{
return Convert.ToBoolean(MembershipService.ValidateUser(UserName, Password));
}
the client is having the following code.
public Boolean ValidateUser(string UserName, string Password)
{
return Convert.ToBoolean(__context.Execute<Boolean>(new Uri(string.Format("{0}ValidateUser?UserName='{1}'&Password='{2}'", __context.BaseUri, UserName, Password))));
}
I am getting error:
Unable to cast object of type 'System.Data.Services.Client.QueryOperationResponse`1[System.Boolean]' to type 'System.IConvertible'.
Have tried to google, but not much info on the error, please can any one suggest me right direction, or solutions, links, articles.....
Thank you in advance.
The Execute returns IEnumerable, so that can't be converted to bool using the Convert.ToBoolean. You need to call .Single() on it, to get the first (and only) item in it.
精彩评论