Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig Taylor 29 posts 69 karma points
    Mar 16, 2011 @ 19:52
    Craig Taylor
    0

    Access Umbraco Content from WCF Service

    What I'm trying to accomplish is relatively simple, but I'm clearly missing something in putting all the pieces together.

    Here's what I've got:

    Umbraco 4.5.2
    Business Logic Layer (BLL)
    WCF Service
    Windows Service

    My site is working great when you just view the site.  My code uses the BLL flawlessly and everything works great when retreiving information from Umbraco.  I utilize "umbraco.content.Instance" in the code to get a lot of the access I need.

    My problem is with my WCF service.  This service attempts to call a method w/in the BLL and is failing because the reference to "umbraco.content.Instance" is null.  This is the same method the 'regular' website calls with no issues.  I realize this is probably a context issue, but don't know how to resolve it.

    My original configuration had my WCF service hosted in its own web application, separate from Umbraco.  I've since read a bunch of posts here about WCF and see that a lot of people integrate them into their Umbraco instance.  I've since placed the DLL in my umbraco bin directory and placed the svc file in a folder off my root called "/services/."  I've added this to the "~/services/" string to the umbracoReservedPaths key and have added relevant web.config entries regarding the service.

    I'm able to browse to my service (now w/in Umbraco) fine using a browser.

    I am not able to get this to work from my test application, however.  When I attempt to make the method call in my BLL, I am now getting an "Object reference not set to an instance of an object at umbraco.presentation.UmbracoContext.get_Current()" error.  Eventually, my windows service will be calling this WCF directly on a specified interval so that this method in the BLL is called on the same interval.

    So first: Is this how I should be approaching the problem?

    Second: How can I get my BLL to have a reference to the Umbraco content when it is called from a third party?

    Thanks!
    Craig

  • kows 81 posts 151 karma points c-trib
    Mar 16, 2011 @ 20:46
  • Harald Ulriksen 207 posts 249 karma points
    Mar 16, 2011 @ 20:47
    Harald Ulriksen
    0

    Hi,

    have you added the following; In web.config under system.serviceModel add

    <serviceHostingEnvironment aspNetCompatibilityEnabled=”true”/>

    and on your service class 

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

    Also see msdn article Hosting WCF Side-by-Side with ASP.NET

    Also, this http://our.umbraco.org/forum/developers/extending-umbraco/15852-Introducing-WCF-WebHttp-Services-in-NET-4-and-Umbraco might be of use.

    Hope this helps,
    Harald

     

     

  • Craig Taylor 29 posts 69 karma points
    Mar 17, 2011 @ 14:31
    Craig Taylor
    0

    Awesome guys!!  I originally had the "aspNetCompatibilityEnabled" set to "true", but removed at one point while trying to get it all working.  What I didn't have, however, was the requirements mode set on the class.

    It's working great now!

    Thank you!

    Craig

Please Sign in or register to post replies

Write your reply to:

Draft