如何强制__type信息在反序列化的JSON响应中呈现?我没有必要重新序列化这些数据,所以我更愿意删除它.ServiceStack似乎将此添加到我的模型的字典属性中.
这是使用ServiceStack和ServiceStack.Text.JsonSerializer
我想通过HTTPS使用基本身份验证来验证我的servicestack.net休息服务的用户.
任何人都可以解释这个https部分如何工作或指向正确的方向?客户有责任确保通过https拨打电话吗?我是否需要执行涉及SSL证书的任何操作才能启用此功能?
如果重要的话,这项服务很可能会在AppHarbor上运行.
编辑
任何人都可以引用如何在服务堆栈中完成此操作的具体示例.我认为我的api中的所有服务都需要HTTPS.我能使用请求过滤器完成此操作吗?
我是Redis的新手(在托管服务中使用它),并希望将其用作列表的演示/沙箱数据存储.
我使用下面的代码.这个对我有用.但是对于一个拥有多个(最多100个)并发用户(对于少量数据 - 最多1000个列表项)的小型网站来说,这是一种有效(而非完全不好的做法)用法吗?
我正在使用静态连接和静态redisclient类型列表,如下所示:
public class MyApp
{
private static ServiceStack.Redis.RedisClient redisClient;
public static IList<Person> Persons;
public static IRedisTypedClient<Person> PersonClient;
static MyApp()
{
redisClient = new RedisClient("nnn.redistogo.com", nnn) { Password = "nnn" };
PersonClient = redisClient.GetTypedClient<Person>();
Persons = PersonClient.Lists["urn:names:current"];
}
}
Run Code Online (Sandbox Code Playgroud)
这样做我有一个非常容易使用的持久数据列表,这正是我在构建/演示应用程序的基本块时所需要的.
foreach (var person in MyApp.Persons) ...
Run Code Online (Sandbox Code Playgroud)
添加新人:
MyApp.Persons.Add(new Person { Id = MyApp.PersonClient.GetNextSequence(), Name = "My Name" });
Run Code Online (Sandbox Code Playgroud)
我担心(目前)不是我在appstart上将完整列表加载到内存中的事实,而是我与redis主机的连接不遵循良好标准的可能性 - 或者是否存在其他问题我不是意识到.
谢谢
我目前正在评估ServiceStack(在.Net中创建基于休息的服务).其中一个感兴趣的领域是测试方面.我的休息服务将注入一些应用程序服务(目前使用Autofac).我需要的是一种机制来测试其余层并在我的应用层上定义期望(通过MOQ),所以我没有进行集成测试,而是单元测试这一层?
关于如何做到这一点的任何想法?
环境是Visual Studio 2012,ServiceStack,ASP.NET Web应用程序项目(关注https://github.com/ServiceStack/ServiceStack/wiki/Create-your-first-webservice)
通过查看ServiceStack.Examples中的一些类,我注意到大多数服务只包含一个方法.有些覆盖Execute()或者,如果是REST服务,有些覆盖OnPost/Get/Put/Delete().
我应该如何看待做一个完整的API集,如果我有几我需要实现的功能RegisterUser(),RemoveUser(),AddFriend(),RemoveFriend()...每个方法的一个服务?
public RegisterUserService : IService<User> { public object Execute(User> dto) { ... } }
public RemoveUserService : IService<User> { public object Execute(User> dto) { ... } }
public AddFriendService : IService<Friend> { public object Execute(Friend dto) { ... } }
public RemoveFriendService: IService<RequestDTO4> { public object Execute(Friend dto) { ... } }
Run Code Online (Sandbox Code Playgroud)
我很失落如何开始实现完整的API集.我已经阅读了"创建您的第一个Web服务" 的第一个和第二个 Wiki页面,我已经复制了该服务方法.但现在我想制作10或40种服务方法,我不知道该怎么做.
我注意到,实现from IRestService<T>允许你最多4个方法而不是一个 …
假设有两个存储库接口:
interface IFooRepository
{
void Delete(int id);
}
interface IBarRepository
{
void Delete(int id);
}
Run Code Online (Sandbox Code Playgroud)
和IUnitOfWork接口类似:
interface IUnitOfWork : IDisposable
{
void Commit();
void Rollback();
}
Run Code Online (Sandbox Code Playgroud)
使用ServiceStack.ORMLite实现这些接口的最佳实践是什么,以便用户可以像使用它们一样使用它们
MyFooRepository.Delete(4);
// if an Exception throws here, Bar won't be deleted
MyBarRepository.Delete(7);
Run Code Online (Sandbox Code Playgroud)
要么
using (var uow = CreateUnitOfWork())
{
MyFooRepository.Delete(4);
MyBarRepository.Delete(7);
uow.Commit(); //now they are in an transaction
}
Run Code Online (Sandbox Code Playgroud) 是否有可能在没有重大hackery的情况下在Runner中获取ServiceStack请求的原始请求主体?
我正在编写一个oauth服务提供程序,使用新的API(Service and Runner)在ServiceStack上运行.由于OAuth签名的工作方式,我需要为每个请求获取原始请求正文.OAuth保护层已添加到Runner中,因此无效的OAuth请求可以轻松返回空/错误响应,而无需Service类中的任何样板或子类化特殊的"OAuthService"类.
他们如何做到这一点http://api.stackexchange.com/docs/wrapper?我知道这些是ServiceStack驱动的API,但一些代码示例会很好.
我想用ASP.NET Web API实现类似的东西.
但是,如果有人可以提供使用ServiceStack实现的StackExchange代码,例如仅供参考,那也可以.
rest asp.net-mvc servicestack asp.net-web-api stackexchange-api
在AppHost上调用Init()时出现上述错误.
这是一个干净的asp.net v 4.5空Web应用程序,它带有一个简单的HelloWorld服务,根据入门教程.
我特意使用安装的旧版ServiceStack:
Install-Package ServiceStack -Version 3.9.71
Run Code Online (Sandbox Code Playgroud)
哪个安装引用:
ServiceStack.dll 3.9.70.0
ServiceStack.Common.dll 3.9.9.0
ServiceStack.Interfaces.dll 3.9.9.0
ServiceStack.OrmLite.dll 3.9.14.0
ServiceStack.OrmLite.SqlServer.dll 1.0.0.0
ServiceStack.Redis.dll 3.9.11.0
ServiceStack.ServiceInterface.dll 3.9.70.0
ServiceStack.Text.dll 4.0.11.0
Run Code Online (Sandbox Code Playgroud)
而我得到的错误是:
[TypeLoadException: Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
Falck.WebAPI.AppHost..ctor() in c:\inetpub\wwwroot\WebAPI\Falck.WebAPI\Global.asax.cs:17
Falck.WebAPI.Global.Application_Start(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebAPI\Falck.WebAPI\Global.asax.cs:29
[HttpException (0x80004005): Could not load type 'ServiceStack.ServiceHost.IService' from assembly 'ServiceStack.Interfaces, Version=3.9.9.0, Culture=neutral, PublicKeyToken=null'.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9865825
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext …Run Code Online (Sandbox Code Playgroud) 免责声明 - 这与Docker容器即使在.net核心控制台应用程序中使用Console.ReadLine()立即退出几乎是同一个问题- 但我不认为这个问题的接受答案是令人满意的.
我想要实现的目标
我正在构建一个控制台应用程序(它是一个使用ServiceStack的HTTP服务),它是用.NET内核构建的(dnxcore50 - 这是一个控制台应用程序,而不是ASP.NET应用程序).我在Linux机器上的docker容器中运行此应用程序.我已经完成了,HTTP服务正常工作.
我的问题
说过"我的服务有效" - 确实如此,在docker容器中托管服务存在问题.我Console.ReadLine()在启动HTTP侦听器后使用,但此代码不会在docker容器中阻塞,并且容器将在启动后立即退出.我可以在"交互"模式下启动docker容器,服务将在那里监听,直到我终止交互式会话,然后容器将退出.
Repo
代码下面的代码是用于创建测试.NET核心服务堆栈控制台应用程序的完整代码清单.
public class Program
{
public static void Main(string[] args)
{
new AppHost().Init().Start("http://*:8088/");
Console.WriteLine("listening on port 8088");
Console.ReadLine();
}
}
public class AppHost : AppSelfHostBase
{
// Initializes your AppHost Instance, with the Service Name and assembly containing the Services
public AppHost() : base("My Test Service", typeof(MyTestService).GetAssembly()) { }
// Configure your AppHost with the necessary configuration and dependencies your App needs
public …Run Code Online (Sandbox Code Playgroud)