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);
}
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.
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
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).
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%.
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/
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
Cheers,
Ranjit
If you're using v6, try creating a an instance of the UmbracoHelper class:
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!
:)
Do you have an example of the ContentCache? Is the NodeFactory swappable with this 'ContentCache'?
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
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
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%.
Did you enable ASP.NET compatibility?
I would actually recommend using WebAPI over WCF since it's much easier to configure. It works well with ASP.NET webforms.
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
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
Sure Lennart, I will a give a shot. :)
Thanks Again!
R
is working on a reply...