2011-03-18 56 views
2

我只想知道如何從wcf數據服務返回一個實體?從wcf數據服務返回單個實體

我想提供一種方法public User Login(string username, string password)並將登錄用戶返回給用戶界面。

謝謝!

andi

+0

看起來像WCF的常見任務。你有沒有嘗試製作一個原型?你真的有任何代碼與我們分享?否則,你的帖子確實沒有內容。 – 2011-03-18 17:16:50

+0

不,這不是一個普通的任務。事實上,這在數據服務中是不可能的。 – 2011-12-14 11:41:11

回答

-1

我認爲這對你有幫助。

我假設用戶是你的實體表。

public User Login(string username,string password) 
{ 
    Entity obj = new Entity(); 
    User objUser = (from U in obj.User where U.username = username and U.password = password Select U).Single(); 
    return objUser; 
} 

這對我很好,我希望它可以幫助你。

2

老問題是舊的,但你要定義一個Service Operation

[WebGet] 
[SingleResult] 
public User GetAuthenticatedUser(string username, string password) { 
    // 
    // Fetch and return the user 
    // with the given parameters 
    // 
} 

然而usernamepassword以明文形式通過URI傳遞。一個更好的選擇是從HTTP請求的Authorization報頭中提取usernamepassword數據,通過線路加密請求(SSL)。一個簡單的例子可以被定義用於數據服務的構造,並在其連接到ProcessingRequest事件:而不是接受它們作爲

public MyDataService() { 
    this.ProcessingPipeline.ProcessingRequest += (o, e) => { 
     // 
     // Do stuff with e.OperationContext.RequestHeaders["Authorization"] 
     // storing the result into an instance property 
     // 
    }; 
} 

隨着引用爲usernamepassword授權特性的User GetCurrentUser()服務操作, GET查詢字符串參數。

+0

您忘記提及寫入SingleResult聲明的文件是什麼。 – Paul 2015-11-20 15:18:17