find a location for property in a new city

Wednesday 15 December 2010

WCF Data Services for using Entity Framework over REST web services

I spent some time looking into WCF Data Services 4.0 (AKA ADO.NET Data Services & Astoria) as a way to expose our Entity Data Model (EDM) over an easy to create set of RESTful / OData web services. I decided to document my findings.

WCF Data Services 4.0 is service that provides a way of exposing an EDM over RESTful (OData) web services using WCF. It means that if you have an EDM already built, the work is essentially done. The EDM can be exposed using WCF Data Services so that it can be queried directly by the client.

How to begin

I successfully set up some WCF Data Services to expose a Comment part of my model. This helped me. I did find difficulty due to our use of POCOs instead of raw Entity Framework's generated code but I found a post that helped which told me about a weird hack that overrides the CreateDataSource into the Data Service:
public class CommentsService : DataService<SocialEntities>
{
    protected override CommentingEntities CreateDataSource()
    {
        var context = new CommentingEntities();
        var tracestring = context.CreateQuery<Comment>("CommentingEntities.Comments").ToTraceString();
        return context; 
    }
}

Consuming the web services

A client can now access the data by requesting URLs. E.g. http://api.mysite.com/CommentsService.svc/Comments to get a list of messages or http://api.mysite.com/CommentsService.svc/Comments(413L) to get the message with ID 413 (the L is for long since I use long instead of int)

The querying gets a lot more complicated than that too. See how to use your browser to query the data model

There are many SDKs out there to begin developing against your WCF Data Services from a number of popular platforms since it is simply using the OData protocol (e.g. JavaScript, PHP, Ruby, Java, Objective-C, .NET).

Restricting use

You can restrict the number of results to return when returning a list of entities to, say 5, so the client can't overload the server/bandwidth.

You can also restrict access to select parts of your EDM to calm your security nerves too:
public static void InitializeService(DataServiceConfiguration config)
{
    config.SetEntitySetAccessRule("Comments", EntitySetRights.AllRead);
}

Evaluating when to use WCF Data Services

So it does look like a great way to use the existing EDM to instantly have a set of RESTful web services to consume. However I think I would only use this if the developers of the web service client were have knowledge of the data and are expecting to get stuck into some code when consuming our data services.

If were internally designing our own Silverlight apps then this is great. However, expecting an external user to write sometimes complex queries to get to our data using all of our business rules (e.g. IsDeleted = false && SiteID = 21) is a little much to be expected I feel.

Conclusion

So great when providing RESTful web services to a handful of specific clients who have knowledge of your data and business logic. Not so great for making a friendly API for the masses based on a complex EDM as you cannot expect them to understand your business rules as well as you do.

I am not claiming authority on this topic. I am just discussing my findings so far in the hope that you may find this useful. If you have anything you think I have missed please feel free to comment.

Follow britishdev on Twitter

63 comments:

  1. you can encapsulate and offer target data services

    ReplyDelete
  2. Ensure business congruity. For instance, an unprotected PC can get to be contaminated and obliterate information that you have to maintain your business.
    https://goo.gl/T1KELS

    ReplyDelete
  3. So, if you want to cut the maximum ice, then you need professional SEO service to cater to your web design needs. SEO companies leave no stone unturned while delivering their service.
    learn web design

    ReplyDelete
  4. The WCF programming model binds together Web Services, .NET Remoting, Distributed Transactions, and Message Queues into a solitary Service-arranged programming model for disseminated figuring. https://www.essaytigers.co.uk/

    ReplyDelete
  5. He's going to look into it for me. Yeah . . . don't speak too soon.Visit Websites

    ReplyDelete
  6. Do you know a framework for paper writing? I need it for my writemypaper-forme.com college project

    ReplyDelete
  7. Very helpful article, thanks for sharing.
      GoMovies

    ReplyDelete
  8. CellAlpha is a One-Stop Platform where you can find genuine reviews. and free books, podcast, many more things

    ReplyDelete
  9. Really this article is very useful and informative for everyone. And I hope you'll share more ideas and useful article with us, If you are looking Best Boot And Glove Dryers. Click Here

    ReplyDelete
  10. Buy Best Quality certeza nebulizer price in pakistan at medisense with affordable prices. Shop Now.

    ReplyDelete
  11. Buy comfortable baby products pakistan at medisense with best price. Shop Now.

    ReplyDelete
  12. Buy Best eye care Products at medisense with best price. Shop Now.

    ReplyDelete
  13. Thanks for sharing... This is Very Nice One And Gives In depth Information... mortgage raising capacity report

    ReplyDelete
  14. you can encapsulate and offer target data services
    mobile price

    ReplyDelete
  15. Thanks for sharing for your valuable information. It is very helpful for us. If you want to know about freelancing so feel free and click here……. Rajshahi IT Center and Rajshahi IT

    ReplyDelete
  16. Really this article is very useful and informative for everyone. And I hope you'll share more ideas and useful article with us, If you are looking Best Boot And Glove Dryers. live score

    ReplyDelete
  17. Thanks for sharing your valuable information. It is very helpful for us. If you want to know about freelancing so feel free and click here……. Rajshahi IT Center and Rajshahi IT

    ReplyDelete
  18. freelancing

    Of course, I'd be happy to provide you with information about freelancing!
    Freelancing refers to a type of employment where individuals offer their services to clients on a project basis, often working independently rather than as employees of a company. Freelancers can provide a wide range of services, including writing, graphic design, programming, marketing, consulting, and more. They are typically not committed to a single employer and have the flexibility to work for multiple clients at once.

    ReplyDelete
  19. freelancing
    freelancing
    Of course, I'd be happy to provide you with information about freelancing!
    Freelancing refers to a type of employment where individuals offer their services to clients on a project basis, often working independently rather than as employees of a company. Freelancers can provide a wide range of services, including writing, graphic design, programming, marketing, consulting, and more. They are typically not committed to a single employer and have the flexibility to work for multiple clients at once.

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. These are some extraordinary devices that I unquestionably use for SEO work. This is an awesome rundown to use later on..
    History of Digital Marketing

    ReplyDelete
  22. These are some extraordinary devices that i unquestionably use for SEO work.Digital marketing IT Center

    ReplyDelete
  23. I'm happy to report that, working with Peter Forshay over the past few months, we've mananged to get the database more-or-less complete up through June 2018, and it's now one of the sources of data for exo.mast. I may continue to make small corrections to the database going forward as a record of where things were in 2018, and I have reason to believe that some new planets will continue to be added to the database from other routes, but June 2018 marks the sunset of regular updates by me and my team.Digital marketing


    ReplyDelete
  24. This post is the philosopher's stone of the internet..
    Global warming

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. This comment has been removed by the author.

    ReplyDelete
  29. This looks great and that's a really good price, especially with such a long guarantee.Sarif’s World

    ReplyDelete
  30. I am very happy for this information
    IT Center

    ReplyDelete
  31. Thanks for sharing... This is Very Nice One And Gives In depth Information. Rajshahi IT Center

    ReplyDelete
  32. This comment has been removed by the author.

    ReplyDelete
  33. This content is very nice and helpful.https://www.pinterest.com

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Understanding the target audience's needs is crucial Daraz here

    ReplyDelete
  37. A very nice post thank you very much.. Internet

    ReplyDelete
  38. I successfully set up some WCF Data Services to expose a Comment part of my model. car price usa

    ReplyDelete
  39. Thanks for sharing... This is Very Nice One And Gives In depth Information. BdIT

    ReplyDelete
  40. Social media is becoming an integral part of online life as social websites and applications proliferate.Mobile price in usa

    ReplyDelete
  41. thamks for sharing your information

    ReplyDelete

  42. Freelancing refers to a type of employment where individuals offer their services to clients on a project basis, often working independently rather than as employees of a company. Freelancers can provide a wide range of services, including writing, graphic design, programming, marketing, consulting, and more.SEO

    ReplyDelete