Entity Framework and WCF – Three ways to play nice together

Standard

Below are the three common issues that always seem to initially catch me out on projects that involve Entity Framework and WCF. They usually manifest themselves with the really helpful error message “The underlying connection was closed…”. You can spin up WCF tracing but generally they all relate to an issue with the serialisation of the types which should be fixed by one of the following:

1) Lazy Loading – Turn it off (YourContext.ContextOptions.LazyLoadEnabled == false).
2) Dynamic Proxies – They don’t play nice over the wire – Turn these off too (ContextOptions.ProxyCreationEnabled == false).
3) Cyclic references – This one is a bit more complicated but nothing that can’t be fixed through a custom attribute on your Operation or Service Contracts. It’s explained in excellent detail with full source code over here.

Remember folks the best way to mitigate these issues is “Integrate early. Integrate often.”

Advertisements

WCF – Your process does not have access rights to this namespace

Standard

Hit this exception whilst trying to spin up a WCF test host in my Windows 7 build. Looks like UAC wants to keep us pinned down but fear not. Run the following at an elevated cmd to sort it:

netsh http add urlacl url=http://+:port/uri user=DOMAIN\user

Subbing in port, uri and in my case I used my logged in user account.

HTH