1

我尝试使用 ServiceStack 和 Sitefinity V3.7sp3 net35 实现一个简单的 web 服务。我使用此 Web配置将 ServiceStack 添加为 localhost/api 。使用 IService 实现服务类后,获取完整的项目 News 内容并注册 Global asax 用于路由。结果总是零项。它与Sf 论坛中的其他帖子非常相似。更改 ContentManager 或提供程序始终返回零项和零作为计数。我的 Sf 允许多语言 en,fr..使用路径。许多需要异步?当然,有人可以帮助我使用 servicestack 来解决这个问题。

问候。

[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;                    
    }
}
4

1 回答 1

0

/api从你的RestService()'s. So like中删除:

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

或者你的网址必须是domain.com/api/api/items...

您已经用 ? 测试了您的网站domain.com/api/metadata

于 2012-07-25T15:11:18.737 回答