none
WCF Data Services, POCO and EF

    Question

  • I've figured out that WCF Data Service coupled with EF and POCO isn't working out of the box according to this post: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/4025b688-2e46-4a08-998c-228c6a11d659

    Basically it says you have to set ProxyCreationEnabled = false. While I've made it work with this setting set to false, I've started investigating how to get it to work with it on. Now, http://blogs.msdn.com/adonet/archive/2010/01/05/poco-proxies-part-2-serializing-poco-proxies.aspx?CommentPosted=true#commentmessage, comes up with a solution for POCO and regular WCF Services, so it makes me think it should be possible with WCF Data Services as well.

    What I've done so far is implementing IRequestHandler explicitly on my WCF Data Service like this:

    public class EntityDataService : DataService<DatabaseEntities>, IRequestHandler

    The actual implementation looks like this:

    [ApplyDataContractResolver]
    public new Message ProcessRequestForMessage(Stream messageBody)
    {
      return base.ProcessRequestForMessage(messageBody);
    }
    This is the closest I can get to the workaround explained in my link. It doesn't work though, and I'm not sure why. That's really besides the point though. Shouldn't it be possible to inject a ProxyDataContractResolver in a WCF Data Service somehow? I just can't wrap my head around how to do it.

    Monday, April 26, 2010 1:27 PM

Answers

  • This isn't possible with WCF Data Services. In WCF, if you are using a contract which takes in a stream and returns a Message, you are basically bypassing all the WCF pipeline and hence one cannot hook into WCF pipleline events such as type resolver.

    This is a bug in WCF data services and needs to be fixed in WCF data service code base.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, April 26, 2010 5:25 PM
    Moderator