开发者

Return single entity from wcf data service

I just wanted to know how to return a single entity from a wcf data service?

I want to provide a methode publi开发者_如何学Goc User Login(string username, string password) and return the loggedin user to the user interface.

Thanks!

andi


Old question is old, but you'll want to define a Service Operation:

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

However the username and password are passed in clear text via the URI. A better option would be pulling the username and password data from the Authorization header of the HTTP request, encrypting the request over the wire (SSL). A simple example could be defining a constructor for the Data Service, and in it attaching to the ProcessingRequest event:

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

With a User GetCurrentUser() service operation that references the authorization property for the username and password, instead of accepting them as GET querystring parameters.


I think this will help you.

I assume User is your entity table.

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

This works fine for me I hope it helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜