MattTheHack
MattTheHack

Reputation: 1384

Accessing Database Entities over a service

I have an Entity Framework database first application running as a WCF service with the following method :

public USER_SESSION GetUserSessionDetails(string ID)
    {
        var ctx = new Entities();
        USER_SESSION user = new USER_SESSION();

        var userSessionDetails = ctx.USER_SESSION.Where(s => s.ID == ID)
                 .Select(s => new { s.USER_NAME, s.DATE_TIME, s.ID }).ToList()
                 .FirstOrDefault();

        user.USER_NAME = userSessionDetails.USER_NAME;
        user.ID = userSessionDetails.ID;
        user.DATE_TIME = userSessionDetails.DATE_TIME;

        if(userSessionDetails == null) {
            return null;
        }
        else {
            return user;
        }

    }

Now, no my client side, I want to access this method and pass the return value into an instance of the USER_SESSION database object like as follows :

USER_SESSION user = new USER_SESSION();
user = serviceClient.GetUserSessionDetails("2");

But my client has no knowledge of what the USER_SESSION object is - How can I access the database entities and objects over a service and use them in my client?

Thanks!

Upvotes: 0

Views: 69

Answers (1)

Shashank Kumar
Shashank Kumar

Reputation: 1220

When u add Service Reference or Service Reference to a Webservice, Proxy Classes of Webservice is Created on Client Application Hence u can access the Model in client also like:

SampleServiceReference.Sample s = new SampleServiceReference.Sample();
label1.Text=s.Name;

Where SampleServiceReference is Your Proxy Webservice Class.You Can View These Classes by selecting The Particular Service Reference and appropriate class

Upvotes: 1

Related Questions