1

I tried to implement a simple webservice using ServiceStack and Sitefinity V3.7sp3 net35. I added ServiceStack as localhost/api using this web config. After implemented the service class using IService to get the full items News contents and registred the Global asax for routes. The result is always zero items. It's very similar to this other post in Sf Forum. Change the ContentManager or the provider is always returning zero items and zero as count. My Sf is allowing multilanguage en,fr..using path. Many be need to be Async?. Can someone help me to fix this case using servicestack of course.

Regards.

[Description("Find items by baseclass, or all default if no genre is provided")]
[RestService("/api/items")]
[RestService("/api/items/news")]
[RestService("/api/items/news/{provider}")]
[RestService("/api/items/news/{provider}/{language}")]
[AspNetCompatibilityRequirements(RequirementsMode =      AspNetCompatibilityRequirementsMode.Allowed)] 
public class Items
{
  public string provider { get; set; }
  public string language { get;set; }
  IList ItemsList{ get; set;  }  
}

/// <summary>
/// Summary description for NewsResponse
/// </summary>
public class ItemsResponse
{
   public ItemsResponse()
   {
   }
   public ResponseStatus ResponseStatus { get; set; } //Automatic exception handling
   public IList Items { get; set; }//return a list of objects
}

/// <summary>
/// Summary description for NewsServices
/// </summary>
public class ItemsService : ServiceStack.ServiceHost.IAsyncService<Items>
{
   //public object Execute(Items request)// with IService
   //{
   //    ItemsResponse response = new ItemsResponse();
   //    response.Items = ItemsList(request.provider,  request.language);//request.provider
   //    return response;
   //  ALWAYS ZERO AS RESPONSE
   //}

   //ERROR ON HANDLER ?    
   object IAsyncService<Items>.ExecuteAsync(Items request)
   {
      ItemsResponse response = new ItemsResponse();
      //if (request.provider != null)
      response.Items = ItemsList(request.baseclass, request.provider, request.language);//request.provider
      return response;    
    }

    public IList ItemsList(string provider, string language)
    {          
        if(provider==string.Empty)
            provider = NewsManager.DefaultContentProvider;
        if (language == string.Empty)
            language = "es";
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(language);
        NewsManager manager = new NewsManager(provider);
        //Get items from this language
        IList data = manager.Content.GetContent();
        return data;                    
    }
}
Slavo
  • 15,255
  • 11
  • 47
  • 60
user325558
  • 1,413
  • 5
  • 22
  • 35

1 Answers1

0

Remove the /api from your RestService()'s. So like:

[RestService("/items")]
[RestService("/items/news")]
[RestService("/items/news/{provider}")]
[RestService("/items/news/{provider}/{language}")]

Or your url would have to be domain.com/api/api/items...

You have tested your site with domain.com/api/metadata?

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69
  • Hi Chuck, The responses from these paths are working, including metadata. The issue is not this but the response retourning zero items. I have commented the Sycn code.It's like if NewsManager.Contents.GetContents() as no time to respond in Sync code. – user325558 Jul 25 '12 at 15:30
  • you removed the null check on `request.provider`, but maybe didn't compensate for that? change first `if` to, `if(string.IsNullOrEmpty(provider)) provider = NewsManager.DefaultContentProvider` – Chuck Savage Jul 25 '12 at 23:06
  • thks chuck i haved rewrite de code but always same issue, no items are retourned. I can see snapshot page with no error and items[{}] emply. The providers are working and tested using ContentManager or NewsManager but is no retourning anything. Tested other languages.I demand me if is not need an Async to be able to return a data, but in this case i need more help to make using servicestack.BR. – user325558 Jul 26 '12 at 12:46
  • You can try to get help here: http://jabbr.net/#/rooms/servicestack The maintainers of SS chat on jabbr – Chuck Savage Jul 26 '12 at 16:01
  • Hi Guys, It seems that this problem is not related to Asyc or Sync but a serialisation problem with Sitefinity and IList emply returned from the ContentManager.Thanks Chuck for your help. – user325558 Jul 27 '12 at 18:22