servicestack

How can I mock ServiceStack IHttpRequest

无人久伴 提交于 2019-12-05 15:16:48
I'm trying to get a unit test working for a service that is injecting items into the IHttpRequest.Items, using a request filter: this.RequestFilters.Add((req, res, dto) => { // simplified for readability... var repo = container.Resolve<IClientRepository>(); var apiKey = req.Headers["ApiKey"]; // lookup account code from api key var accountcode = repo.GetByApiKey(apiKey); req.Items.Add("AccountCode", accountCode); }); My service uses that dictionary item: public class UserService : AppServiceBase { public IUserServiceGateway UserServiceGateway { get; set; } public object Any(UserRequest request

Remove concrete __type information in JSON Response using JsonSerializer

半城伤御伤魂 提交于 2019-12-05 15:03:48
问题 How do you force the __type information from rendering in the deserialized JSON response? I have no need to reserialize this data so I'd prefer to remove it. ServiceStack seems to add this to the dictionary properties of my model. This is using ServiceStack and ServiceStack.Text.JsonSerializer 回答1: By default the __type is only emitted when it's required for deserialization, e.g. your DTO contains an interface, abstract class or late-bound object type, etc. You can prevent it from ever being

Serving a static file with servicestack

给你一囗甜甜゛ 提交于 2019-12-05 14:06:57
How would i go around serving a static file using servicestack? I would like to add a route like Routes.Add(/app) and when a client issues a GET for this path i need to return the a silverlight xap file. mythz ServiceStack is already be able to serve static files by referencing them directly. Otherwise if you want a service return a file for downloading, you can do so with: return new HttpResult(new FileInfo("~/app.xap"), asAttachment:true) { ContentType = "application/x-silverlight-app" }; Note: asAttachment will control whether or not to send HTTP Content-Disposition headers. More info about

Is there a way to authorise servicestack with ASP.NET Identity?

自闭症网瘾萝莉.ら 提交于 2019-12-05 14:00:54
The only example I have found of mutual authentication between ASP.NET MVC and Servicestack involves using Servicestack's built in authentication and setting the cookie for old MVC Forms authentication. I am interested if it is possible to flip this around and authorise servicestack services with the new ASP.NET Identity system. The reason being that I would IDEALLY like to have a simple authentication story and use the same attributes, such as [Authorize] [AllowAnonymous] from Identity with the servicestack API. I don't have experience with either Identity or servicestack plugins so it would

ServiceStack ResponseFilterAttribute not being called

大兔子大兔子 提交于 2019-12-05 13:09:06
//--------------------------------------------------------------------- //Aspect Filters public class RequestAspectAttribute : RequestFilterAttribute { public RequestAspectAttribute() { } //debug point was hit public RequestAspectAttribute(ApplyTo applyTo) : base(applyTo) { } public override void Execute(IHttpRequest req, IHttpResponse res, object reqDto) { //This code is executed before the service //debug point was hit } } public class ResponseAspectAttribute : ResponseFilterAttribute { public ResponseAspectAttribute() { } //debug point was NOT hit public ResponseAspectAttribute(ApplyTo

How to test ServiceStack Service using Moq

♀尐吖头ヾ 提交于 2019-12-05 12:37:13
I have a rest service that I have created with ServiceStack, using nHibernate as a way of getting the data from a SqlCe database. I've been trying to write some unit tests using nUnit and Moq - I have successfully mocked the nHibernate implementation to return null, invalid objects and so on - but my tests always throw a NullReferenceException when it calls the base class to set the HttpStatus etc. public List <ParameterDto> Get (ParameterAll parameterAll) { List <ParameterDto> parameterResponseList = new List <ParameterDto> (); try { List <ParameterDomainObject> parameterDomainObjectList =

Deserializing array from XML data (in ServiceStack)

不打扰是莪最后的温柔 提交于 2019-12-05 12:22:19
I've got the following chunk of XML data: <ArrayOfRESTDataSource xmlns="http://SwitchKing.Common/Entities/RESTSimplified/2010/07" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <RESTDataSource> <Description>MyTest</Description> <Enabled>true</Enabled> </RESTDataSource> </ArrayOfRESTDataSource> RESTDataSource can occur 0-n times. And here's my classes: [DataContract( Namespace = "http://SwitchKing.Common/Entities/RESTSimplified/2010/07" )] public class ArrayOfRESTDataSource { public RESTDataSource[] Data { set; get; } } [DataContract( Namespace = "http://SwitchKing.Common/Entities

ServiceStack 项目实例 000 简介

有些话、适合烂在心里 提交于 2019-12-05 08:46:37
ServiceStack 是一个功能齐全的服务开发套件,接近Java下的SSH的结构和思路,整体类似轻量级的SSH,主要是用于REST模式的接口服务的开发,后文中简称SS。 和SS功能相似的框架有WCF、WebAPI,SS是WCF和WebAPI的有力替代者,效率和功能上超越前两者,但资料和样例较少,并且在4.0版开始收费,但多数情况3.x已足够用,以下是针对3.9.x版本。 SS主要包含REST服务、轻量ORM数据库封装、IoC依赖注入管理,数据压缩加密、二进制传输、权限及认证管理以及asp.net MVC模板支持等功能模块,下面列出一般会用到主要模块和功能: ServiceStack.dll 核心服务模块,提供REST、SOAP等服务,可以兼容WCF。 ServiceStack.OrmLite 轻量数据库访问模块,支持多种数据库,有独有的数据优化方案。 ServiceStack.Redis NoSQL数据库访问模块,内部包含有队列服务支持,通常可用于大数据的数据缓存支持。 ServiceStack.Interfaces 接口功能模块,可以通过接口扩展和增加功能以及模块,并且支持动态加载和插件模式。 Funq 第三方依赖注入库,类似Spring或nSpring的功能,具备类自动装配功能,并可自定装配规则。 【身份验证和权限管理】 ServiceStack

How do we integrate elmah logging in servicestack

跟風遠走 提交于 2019-12-05 08:32:58
I am new to servicestack and elman logging. Can any body suggest how do we integrate elmah in service stack applications. Thank you... If you have an existing logging solution then you can use the ServiceStack.Logging.Elmah project. It is available via NuGet. Exceptions, errors and fatal calls will be logged to Elmah in addition to the originally intended logger. For all other log types, only the original logger is used. So if you are already using Log4Net then you can just configure Elmah like this ElmahLogFactory factory = new ElmahLogFactory(new Log4NetFactory()); If you don't want to wrap

Documenting ServiceStack web services [closed]

核能气质少年 提交于 2019-12-05 08:26:16
What are the options for documenting a ServiceStack bases web services and I'm not talking about a one line string. I would like to be able to document, in detail (which can be long), return types, possible HTTP responses, add detailed examples etc. Is there any support for this in ServiceStack (I couldn't find it)? If not has anybody solved the problem in some other way. You can provide metadata descriptions for each of your web services by attributing your Request DTOs with [Api] and [ApiMember] attributes. This information will be displayed on the dynamic metadata pages. Another option is