views:

134

answers:

2

Hi there,

I need to extend my WCF Data Service to include additional methods, not only the database tables..

But it doesn't seem to be working correctly.

Firstly i want to ask if this is legal? or throwned upon?

The reason i need to do it is i need add additional REST methods that will make a call to ASP.NET Membership services (the tables are in the db) to validate a login i.e.

    public bool IsValidLogin(string username, string password)
    {
        return System.Web.Security.Membership.ValidateUser(username, password);
    }

Here is what i have (i have simplied the IsValidLogin for testing).

    [WebGet(UriTemplate = "TestMe")]
    public bool IsValidLogin()
    {
        return true;
    }

    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config)
    {
        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        config.SetServiceOperationAccessRule("IsValidLogin", ServiceOperationRights.All);

Now when i go to

  http://localhost/MyDataAccess/MyService.svc/IsValidLogin

It seems to work i get an true back in the form of XML. But i have set a URI so i thought i could do this

  http://localhost/MyDataAccess/MyService.svc/TestMe

But it fails? I am really confused, any ideas?

Also for it to work I needed to add this line, but a little but confused here

    config.SetServiceOperationAccessRule("IsValidLogin", ServiceOperationRights.All);

Any help really appreciated

A: 

The ServiceOperation notion is a tacked on capability to provide exactly the escape you needed when you wanted to do something other than read data from a table.

Unfortunately, the default path in WCF REST has lead you to misunderstand how RESTful systems are supposed to work. REST is not just about exposing some data at URLs.

You really have two choices, either stick with RPC style of distributed computing that WS-*/SOAP based WCF provides or spend some time learning what REST is really all about. There are some links here to get you started.

I can't tell you what is the right approach for your scenario. What I can tell you is that you are not going to learn how to do REST from using the current WCF REST implementation. I'm not saying it is impossible to do, you just will be doing a lot of swimming upstream.

Darrel Miller
Darrel, i think i already have REST sorted now, i have another project that i am working on and all is well... My database is exposed via DataServices. I also need to tap into ASP.NET Membership which are tables (in my case) in the db... so i thought to extend (add to) my data service project to include some rest methods ....
mark smith
If you have further comments i am listening but i really don't see how i have missed the point? can you elaborate? WCF Rest works with http methods like GET,PUT etc.. I have placed a GET as a method and returns some data....
mark smith
@mark If you are trying to do a Login, you are not doing stateless requests. That is a REST constraint. If you are deserializing objects on the client and sending application/xml as the media type (which WCF) does then your requests are not self-descriptive. That's another REST constraint. IsValidLogin violates the Resource Identification constraint. I'm pretty sure you are not returning hypermedia nor using a hypermedia driven client so HATEOAS is probably not high on your list of design objectives. Honestly, I'm not saying what you are doing is wrong, just don't think it is REST.
Darrel Miller
Thanks Darrel for the comments, I am not doing a login.. The login is done on the client i am only a request to a web service (in this case REST) and REST returns XML weather it is a valid login or not...Regarding deserializing objects, well i not really doing that.. the rest returns XML and i am using a .net class to populate a .net object from the XML returned by the rest.Thanks for your comments.. i will try and investigate further
mark smith
A: 

Not commenting on the REST dicsussion above, just posting a link on documentation on how to do so called "service operations": http://msdn.microsoft.com/en-us/library/cc668788.aspx

Vitek Karas MSFT