我正在创建一个移动应用程序,它需要一个API服务后端来获取/放置每个用户的信息.我将在ServiceStack上开发Web服务,但对存储感到疑惑.我喜欢像Redis这样快速内存缓存系统的想法,但我有几个问题:
我是第一次构建服务堆栈:hello world.
但它给了我一个错误:找不到请求处理程序:可能缺少的部分是什么?谢谢.
这是我的global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using ServiceStack.ServiceHost;
using ServiceStack.WebHost.Endpoints;
namespace ServiceStack.SearchService
{
public class Global : System.Web.HttpApplication
{
public class Hello { public string Name { get; set; } }
public class HelloResponse { public string Result { get; set; } }
public class HelloService : IService<Hello>
{
public object Execute(Hello request)
{
return new HelloResponse { Result = "Hello, " + request.Name }; …Run Code Online (Sandbox Code Playgroud) 我目前正在努力ServiceStack,对它来说很新.(非常有趣;他们说他们比WCF和REST WCF(GET,POST,PUT,DELETE)更好)
我发现它很有帮助,只需要很少的代码就可以快速运行它.
目前我想发布数据.我制作类的对象并发送POST请求.
JsonServiceClient client = new JsonServiceClient(myURL);
MYclass cls= MakeObjectForServiceStackToInsertData();
var res = client.Post<MYClass>("/postrequest", cls);
Run Code Online (Sandbox Code Playgroud)
通过上面的代码你可以理解,我正在做的事情是什么.我想我没错.如果你感到困惑,请告诉我.
我可以(KEY->Value)在我的客户端应用程序中为我的类创建一个JSON字符串(手动),并使用服务堆栈将其发送到服务器以发送数据.
即
string str = myJsonString();
var res = client.Post<.....>
Run Code Online (Sandbox Code Playgroud)
因此,如果我可以在ServiceStack的POST事件中生成JSON字符串并对其进行反序列化并在数据库中插入数据,那么不是发布整个对象,而是发布它.
任何的想法?
我正在设计一个使用Redis作为数据库的Web服务,我想知道使用Redis连接StackService客户端的最佳实践.
关键是我一直在阅读Redis,我发现与服务器交互的最佳方式是使用单个并发连接.
问题是,尽管每次Web客户端向Web服务发出请求时我都在使用PooledRedisClientManager,但我得到了一个连接到redis服务器的连接客户端(打开的连接),并且这个连接的客户端数量增加了更多的记忆.
样本'故障'代码:
PooledRedisClientManager pooledClientManager = new PooledRedisClientManager("localhost");
var redisClient = pooledClientManager.GetClient();
using (redisClient)
{
redisClient.Set("key1", "value1");
}
Run Code Online (Sandbox Code Playgroud)
我为解决这个问题所做的是创建一个用静态RedisClientvar 实现单例模式的类; 如果redisClient未初始化,则创建一个新的,如果是,则返回初始化的.
解:
public class CustomRedisPooledClient
{
private static CustomRedisPooledClient _instance = null;
public RedisClient redisClient = null;
// Objeto sincronización para hacer el Lock
private static object syncLock = new object();
private CustomRedisPooledClient()
{
redisClient = new RedisClient("localhost");
}
public static CustomRedisPooledClient GetPooledClient()
{
if (_instance == null)
{
lock (syncLock)
{
if …Run Code Online (Sandbox Code Playgroud) ServiceStack OrmLite究竟是如何处理默认和计算列的?
具体来说,我收到了错误
The column "PointsAvailable" cannot be modified because it is either a computed column or is the result of a UNION operator.
Run Code Online (Sandbox Code Playgroud)
此列配置为SQL Server 2008数据库中的计算列.
OrmLite似乎对计算列做了一些事情,因为您可以将属性'[ServiceStack.DataAnnotations.Compute]'添加到模型中的属性.
进入代码,调用'OrmLiteDialetBase.cs'中的函数'ToInsertRowStatement'.当该函数检查是否设置了AutoIncrement属性时,它不检查是否设置了IsComputed属性.
我不知道这是一个错误,还是我错了.
我有一个ID为的实体
public string ID {get;set;}
activities/1
Run Code Online (Sandbox Code Playgroud)
(来自RavenDB).
我在ServiceStack AppHost中注册了以下路由
Routes
.Add<Activity>("/activities")
.Add<Activity("/activities/{id}");
Run Code Online (Sandbox Code Playgroud)
我正在使用骨干应用程序POST和PUT到我的REST服务.
开箱即用的事情:
我知道的选项:
两者都有缺点,我要么在我的API中丢失RESTful,这是不可取的,或者我不遵循RavenDb约定,这通常是明智的狐狸.另外,我个人喜欢使用斜杠.
所以我想知道在servicestack中是否还有其他选项我可以用来解决这个涉及较少妥协的问题?无论是Serialiser定制还是通配路由都在我脑海中......
我想处理WebServiceException我的服务客户端抛出的所有内容.现在有一个很好的方法吗?
例如,我在Windows窗体应用程序周围传递一个ServiceClientBase.我在http标头中将api密钥传递给服务器.对于api密钥无效的任何请求,我想显示一个消息框,告诉用户该请求是未授权的,他们应该设置API密钥.但我不希望这个代码到处都是:
try
{
_client.Get(new ReqDto());
}
catch (WebServiceException ex)
{
if(ex.StatusCode == 401)
Util.ShowUnauthorizedMessageBox();
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西会很好:
_client.WebServiceExceptionHandler += TheHandler;
Run Code Online (Sandbox Code Playgroud)
我知道有可以挂钩的本地响应过滤器,但我需要物化的WebServiceException.
我正在看ServiceClientBase.cs看看我能做些什么,但我很感激任何帮助.谢谢.
我们使用多租户ServiceStack创建API .我们希望进行基于DNS的负载平衡和路由,而不是通过反向代理(如nginx或haproxy)来解决问题.
我们有请求DTO具有租户参数.ServiceStack(及其SwaggerFeature)允许我们定义自定义路由,并记录DTO,以便我们可以从路径,查询,标题或正文中读取值.
我们如何(最好)连接东西,以便DTO属性也可以从主机名模式中读取值?那么,让Route从匹配的主机名和路径中获取值?
我们想要像这样的网址
https://{tenant}.{DNS zone for environment}/{rest of path with tokens}此外,DNS区域将根据我们所处的环境而变化 - 对于我们使用的非生产(比如说)testing-foobar.com和我们使用的生产real-live.com.理想情况下,我们能够通过单个路由声明支持两者(我们更喜欢在运行时装饰Request DTO而不是命令式声明AppHost.Init).
I work on a few .NET web apps that use Redis heavily for caching along with ServiceStack's Redis client. In all cases I've got Redis running on the same machine. I've used both BasicRedisClientManager and PooledRedisClientManager (always implemented as singletons) and have had some issues with both approaches.
With BasicRedisClientManager, things would work fine for a while, but eventually Redis would start refusing connections. Using netstat we discovered that thousands of TCP connections to the default Redis port were …
有没有正确的方法来更新IRedisList?使用下面的示例代码,我可以修改它以删除列表,更新比萨饼并重新添加列表,但这感觉不对.命令行文档很漂亮,但这是一个比我更大的项目,我不完全确定从哪里开始寻找.
public void UpdatePizza(Pizza pizza)
{
using (var redisClient = new RedisClient(Host, Port))
{
IRedisTypedClient<Pizza> redis = redisClient.As<Pizza>();
IRedisList<Pizza> pizzas = redis.Lists["pizzas:live"];
var toUpdate = pizzas.First(x => x.Id == pizza.Id);
toUpdate.State = pizza.State;
//??How to save
}
}
Run Code Online (Sandbox Code Playgroud) servicestack ×10
redis ×4
c# ×3
asp.net ×1
binding ×1
ravendb ×1
rest ×1
routing ×1
sql-server ×1
web-services ×1