servicestack

ServiceStack.Redis高效封装和简易破解

拜拜、爱过 提交于 2019-11-30 18:03:27
1.ServiceStack.Redis封装 封装的Redis操作类名为RedisHandle,如下代码块(只展示部分代码),它的特点: 1)使用连接池管理连接,见代码中的PooledClientManager属性。如果不用连接池,而是代码直接RedisClient client = new RedisClient("localhost", 6379, "password");去获取一个连接实例操作,那么当Redis操作频繁时,代价很大,不可行。 2)支持读写分离的Redis服务端(如果你只用一个Redis服务端,那么读写服务端连接字符串一样即可)。 3)操作Redis时,自动切换读写Redis连接实例,见代码中的GetRedisClient函数,所有写操作取“写连接实例”PooledClientManager.GetClient(),所有读操作取“读连接实例”PooledClientManager.GetReadOnlyClient()。 注意:如果你读写是两个做了主从复制的Redis服务端,那么要考虑主从复制是否有延迟,是否有一些读操作要求实时数据,如果是,那么需要在GetXX读数据时用写连接实例。这时候,可以改写此GetXX函数,可在函数参数末尾增加 bool? isReadOnly = null 带默认值的参数,即支持外部调用指定用哪种连接实例操作

ServiceStack OAuth - registration instead login

蹲街弑〆低调 提交于 2019-11-30 16:11:49
In servicestack OAuth implementation I only saw possibility to automatically login with eg. facebook account. But is there abbility to support registration process with facebook login. What I wanted is to let users login to facebook app, and then load their Name, Surname and email and prefill needed text boxes for real registration on my site (since I also have to have mobile phone verification etc.) I don't want user to be authorized and authenticated when he logs in with facebook. Only credentials login should be valid one for full site access. Edit: I found a solution. In FacebookProvider

Html5 pushstate Urls on ServiceStack

二次信任 提交于 2019-11-30 15:37:53
At the moment we're using a default.cshtml view in the root of ServiceStack to serve our AngularJS single-page app. What I'd like to do is enable support for html5 pushstate (so no hash in the URL), but the only examples I've found so far involve a dependency on MVC with a wildcard route, and pushing the ServiceStack infrastructure to a /api subroute. We can't take the MVC dependency, so I think we need for accept:text/html requests we need to accept any url and serve up our root application. I'd be happy to remove the default HtmlFormat extension or override it (we could still use it's

Get HttpResult using the JsonServiceClient

拟墨画扇 提交于 2019-11-30 15:28:32
I am returning HttpResult from one of the rest service methods using servicestack's new API. Is there a way to get the HttpResult using the JsonServiceClient? For ex: JSonServiceClient.Send<HttpResult>("DELETE","person", new { PersonID = 30 }); I want to inspect the header information from the httpresult. Thanks. There's no such thing as a HttpResult client response from a ServiceStack web service. You use a HttpResult to customize the HTTP Response that's returned from your service, e.g. Add additional HTTP Headers. But the response body the client sees is still only the Response DTO (if any)

Service Stack on MVC4

随声附和 提交于 2019-11-30 14:43:46
问题 I am just trying to get Service Stack running under a mvc4 project. Does the ServiceStack.Host.Mvc nuget package work with mvc 4.0 ? I installed it and added the routes.IgnoreRoute("api/{*pathInfo}"); to the routing config but it does not find the route when I go to /api/metadata and I get the error: No HTTP resource was found that matches the request URI 'http://localhost:51681/api/metadata'. 回答1: Found the solution. Whenever we are creating new asp.net mvc4 project it comes with Asp.Net Web

Catching exceptions with servicestack

天涯浪子 提交于 2019-11-30 14:38:48
We have been using ServiceStack for REST based services for a while now and so far it has been amazing. All of our services have been written as: public class MyRestService : RestService<RestServiceDto> { public override object OnGet(RestServiceDto request) { } } For each DTO we have Response equivalent object: public class RestServiceDto { public ResponseStatus ResponseStatus {get;set;} } which handles all the exceptions should they get thrown. What I noticed is if an exception is thrown in the OnGet() or OnPost() methods, then the http status description contains the name of the exception

Can't get Visual Studio 2013 browser link working with static html

扶醉桌前 提交于 2019-11-30 14:35:27
I've been having trouble getting Visual Studio's browser link functionality to work consistently. The projects I've tried it in have all used Service Stack and Angular. I've added the handler in the system.webservice section but still nothing. <handlers> <add name="Browser Link for HTML" path="*.html" verb="*" type="System.Web.StaticFileHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" resourceType="File" preCondition="integratedMode" /> </handlers> I found the answer! It turns out that something with the tag in the web.config is a bit different. I had

Create route for root path, '/', with ServiceStack

房东的猫 提交于 2019-11-30 14:00:21
问题 I'm trying to set a RestPath for root, '/', but its not allowing me to. Its saying RestPath '/' on Type 'MainTasks' is not Valid Is there a way to allow this? I'd like to provide a resource from the root. [Route("/", "GET")] public class MainTasks : IReturn<MainTasksResponse> { } 回答1: You can only match on the Route / Path in ServiceStack with a FallbackRoute, e.g: [FallbackRoute("/{Path*}")] public class Fallback { public string Path { get; set; } } This uses a wildcard to handle every

Return a custom auth response object from ServiceStack authentication

六眼飞鱼酱① 提交于 2019-11-30 13:01:35
Is it possible to return a custom auth response? I already have my own custom authentication provider that inherits from CredentialsAuthProvider. I want to return the session expiry date in the response, so that the client knows exactly when their server session will expire: { "sessionId": "bG27SdxbRkqJqU6xv/gvBw==", "userName": "joe.bloggs@letmein.com", "sessionExpires": "2013-04-29T03:27:14.0000000", "responseStatus": {} } I can override the Authenticate method like so: public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request) { // get base response

Best practices of implementing unit of work and repository pattern using ServiceStack.ORMLite

China☆狼群 提交于 2019-11-30 12:18:48
Supposing that there are two repository interface : interface IFooRepository { void Delete(int id); } interface IBarRepository { void Delete(int id); } And an IUnitOfWork interface like : interface IUnitOfWork : IDisposable { void Commit(); void Rollback(); } what is the best practices of implementing those interface using ServiceStack.ORMLite so that user can use them like MyFooRepository.Delete(4); // if an Exception throws here, Bar won't be deleted MyBarRepository.Delete(7); Or using (var uow = CreateUnitOfWork()) { MyFooRepository.Delete(4); MyBarRepository.Delete(7); uow.Commit(); //now