Copied to clipboard

Flag this post as spam?

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


  • Ranjit J. Vaity 66 posts 109 karma points
    Oct 11, 2013 @ 15:32
    Ranjit J. Vaity
    0

    Umbraco 6, WCF service call and (NiceUrl ?)

    Hello,

    I had good exposure in Umbraco 3,4 but being first one in v6, Need little guidance. This project us using Webforms and not Mvc.

    Success till now: I am implementing search functionality in my current project which includes pagination. For better user experience I decided to go with pulling search results using WCF service and using jQuery Ajax calls. I am able to send and receive data (only content.Name) to and from the service.

    Issue: In search item PageTitle(property), Description(property) and Url(Link to page) needs to be in place. I am not able to find suitable method call (like niceUrl) in IContent, any other similar class.

    Please advise how should I get niceUrl for pageIds returned by Examine/Lucene and what should be the best practice of implementation in this scenario.

    Thank you to this excellent forum ! :)

    code snippet:

    List

    List

            foreach (SearchResult item in results)
            {
                dynamic processedItem = new ExpandoObject();
                var content = ApplicationContext.Current.Services.ContentService.GetById(item.Id);
                processedItem.Title = content.Name;
                processedItem.Url = umbraco.library.NiceUrl(content.Id); /* troubling me */
                processedItem.ShortDescription = content.Properties["ShortDescription"]; /* troubling me */
                processedList.Add(processedItem);
            }
    

    Cheers,

    Ranjit

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Oct 11, 2013 @ 16:03
    Tim
    0

    If you're using v6, try creating a an instance of the UmbracoHelper class:

    UmbracoHelper help = new UmbracoHelper(UmbracoContext);
    

    This has a lucene search method called "TypedSearch" that you can use to get back a list strongly typed IPublishedContent objects that have access to the .Url() method.

    In your code, you are using the Content Service, which hits the database to get the content. Unless you want unpublished content, you'd be much better off using the ContentCache instead, which runs off the front end content cache and is MUCH faster.

    Hope that helps!

    :)

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Oct 11, 2013 @ 16:28
    Stefan Kip
    0

    Do you have an example of the ContentCache? Is the NodeFactory swappable with this 'ContentCache'?

  • Ranjit J. Vaity 66 posts 109 karma points
    Oct 14, 2013 @ 14:32
    Ranjit J. Vaity
    0

    Hi Tim,

    Thank you for your response.

    To put across little more in breif, I am trying to fire search in WCF service and convert the data received in JSON format to send it across to SearchResults page.

    In here, It's Umbraco 6 but I did neither MVC nor razor. Just web forms.

    when execution reaches:

    UmbracoHelper help = new UmbracoHelper(UmbracoContext.Current);

    it terminates an does not throw any exception, very much like 

    processedItem.Url = umbraco.library.NiceUrl(content.Id);

    I know that sounds wierd.

    Please advice!

    Thanks,

    Ranjit

  • Ranjit J. Vaity 66 posts 109 karma points
    Oct 14, 2013 @ 15:38
    Ranjit J. Vaity
    0

    after setting try...catch around, UmbracoHelper help = new UmbracoHelper(UmbracoContext.Current); throws exception "Value cannot be null. Parameter name: umbracoContext" This error is in WCF service (.svc.cs file).

     

    Thanks,

    Ranjit

     

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Oct 14, 2013 @ 18:27
    Tim
    0

    Hi Ranjit,

    I've had a look and it looks like UmbracoContext.Current doesn't get set when you're outside of the main Umbraco context (which you will be in a WCF service). I'm not sure if there's a way to instantiate it in a WCF service.

    You could maybe look at using a WebApi controller in Umbraco instead of WCF? That might work, but I'm not 100%.

  • Lennart Stoop 304 posts 842 karma points
    Oct 14, 2013 @ 18:53
    Lennart Stoop
    100

    Did you enable ASP.NET compatibility?

    <configuration><system.serviceModel><serviceHostingEnvironmentaspNetCompatibilityEnabled="true"/></system.serviceModel></configuration>

    I would actually recommend using WebAPI over WCF since it's much easier to configure. It works well with ASP.NET webforms.

  • Ranjit J. Vaity 66 posts 109 karma points
    Oct 28, 2013 @ 14:17
    Ranjit J. Vaity
    0

    Hi Lennart,

    Thank you for the hint, its working fine now..... :)

    Along with above suggestion, I also had to add following attribute on which I alway try to find an alternative.

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    Will give a shot on WebAPI. Could you please suggest the few of the good resources on WebAPI that I can go through?

    Thank you again!..

    Ranjit J. Vaity

     

  • Lennart Stoop 304 posts 842 karma points
    Oct 29, 2013 @ 09:21
    Lennart Stoop
    0

    Hi Ranjit,

    Good to hear you got it working!

    Using Web API is pretty straightforward, basically you just create a controller which derives from the ApiController class, configure a route for the controller in the Application_Start (Global asax) and you're done. More info and detailed examples can be found at http://www.asp.net/web-api

    Note that if you're using Umbraco 6.1+ it's easier to inherit from the Umbraco ApiController class which already exposes the Umbraco context and helper classes you might need. More info @ http://our.umbraco.org/documentation/Reference/WebApi/

    Grtz

    L

  • Ranjit J. Vaity 66 posts 109 karma points
    Nov 02, 2013 @ 07:20
    Ranjit J. Vaity
    0

    Sure Lennart, I will a give a shot. :)

    Thanks Again!

    R

Please Sign in or register to post replies

Write your reply to:

Draft