2011-03-31 89 views
0

我已經創建了一個WCFDataService,併爲用戶驗證提供了一個自定義webget方法,使用它從wpf應用程序中進行驗證。WCFDataService無法轉換

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)); 
} 

客戶端有以下代碼。

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)))); 
} 

我正在錯誤:

無法轉換類型的對象 'System.Data.Services.Client.QueryOperationResponse`1 [System.Boolean]' 爲類型 'System.IConvertible'。

是否嘗試過谷歌,但錯誤沒有太多的信息,請任何一個可以建議我正確的方向,或解決方案,鏈接,文章.....

預先感謝您。

回答

1

Execute返回IEnumerable,因此無法使用Convert.ToBoolean轉換爲bool。你需要調用.Single()來獲取第一個(也是唯一的)項。

相關問題