Tag: servicestack

如何让Swagger插件在自托管服务堆栈中工作

我已经通过github提供的示例重新提出了这个问题,并为任何想要自己运行代码的人提供了一个下拉框下载链接: Swagger没有在自托管的ServiceStack服务上工作 我在我的网站解决方案中运行了我的servicestack JSON服务,在’/ api / path下,但现在我想拆分该服务堆栈部分并将其作为自托管Windows服务运行。 我的问题是,我自己和其他开发人员发现Swagger插件对于测试目的非常有用,但现在它是自托管的,似乎HTTPHandler只设置为仅处理服务路由,而纯HTML不起作用。 我该如何解决? URL: http://localhost:8081/Swagger-UI/Index.html 回应: Handler for Request not found: Request.HttpMethod: GET Request.HttpMethod: GET Request.PathInfo: /Swagger-UI/Index.html Request.QueryString: Request.RawUrl: /Swagger-UI/Index.html 安装Nuget包: ServiceStack ServiceStack.Razor @marfarma的更新 我的app.config文件里面没有任何相关的ServiceStack …… Program.cs: AppHostHttpListenerBase appHost = new my.HttpApi.myApiServiceHostBase(“My Service”, “my.ApiService”); string listeningURL = “http://localhost:8081/”; var appSettings = new ServiceStack.Configuration.AppSettings(); my.HttpApi.FakeProvider.ProductProvider.Init(appSettings); my.HttpApi.FakeProvider.UserProvider.Init(appSettings); #if DEBUG try { […]

如何使用Moq测试ServiceStack服务

我有一个使用ServiceStack创建的rest服务,使用nHibernate作为从SqlCe数据库获取数据的方法。 我一直在尝试使用nUnit和Moq编写一些unit testing – 我已经成功地模拟了nHibernate实现以返回null,无效对象等等 – 但我的测试总是在调用基类来设置HttpStatus等时抛出NullReferenceException 。 public List Get (ParameterAll parameterAll) { List parameterResponseList = new List (); try { List parameterDomainObjectList = _ParameterDao.getAllParameters (); foreach (ParameterDomainObject parameterDomainObject in parameterDomainObjectList) { parameterResponseList.Add (parameterDomainObject.ToDto ()); } } catch (WebServiceException webEx) { Debug.WriteLine (“WebServiceException.ErrorCode ” + webEx.ErrorCode); Debug.WriteLine (“WebServiceException.ErrorMessage ” + webEx.ErrorMessage); Debug.WriteLine (“WebServiceException.ResponseStatus ” […]

ServiceStack“新”api和async等待

ServiceStack版本3 我非常熟悉https://github.com/ServiceStack/ServiceStack/wiki/New-API ,在这个页面上它特别说“所有这些API都有异步等价物,你可以在需要时使用它们。” 是否可以使用async等待ServiceStack的新api? 使用异步等待服务器和客户端代码会是什么样的? [Route(“/reqstars”)] public class AllReqstars : IReturn<List> { } public class ReqstarsService : Service { public List Any(AllReqstars request) { return Db.Select(); } } 客户 var client = new JsonServiceClient(BaseUri); List response = client.Get(new AllReqstars()); 有些人请将这些同步示例转换为异步吗?

从XML数据反序列化数组(在ServiceStack中)

我有以下大量的XML数据: MyTest true RESTDataSource可以发生0-n次。 这是我的课程: [DataContract( Namespace = “http://SwitchKing.Common/Entities/RESTSimplified/2010/07” )] public class ArrayOfRESTDataSource { public RESTDataSource[] Data { set; get; } } [DataContract( Namespace = “http://SwitchKing.Common/Entities/RESTSimplified/2010/07” )] public class RESTDataSource { [DataMember] public bool Enabled { get; set; } [DataMember] public string Description { get; set; } } 我从这样的服务器上读取了上面的XML数据: WebRequest client = WebRequest.Create( “http://server:80/datasources” ); […]

ServiceStack在没有MVC的情况下启用Razor intellisense支持

我已经将SS.Razor安装到我的测试项目中。 如果我只是更改default.htm – > cshtml,它可以工作,但没有vs intellisense语法支持。 因此剃刀代码是纯文本黑色和白色。 我想知道如何在不打开作为.net MVC项目的项目的情况下打开Razor。 谢谢! 编辑—————————————— 这是我的web.config (注意add extension =“。cshtml”……有…) <!– For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367. The following attributes can be set on the tag. –> <!– The section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. […]

如何使用ServiceStack JsonSerializer序列化ExpandoObject?

是否有可能让ServiceStack JsonSerializer将ExpandoObject序列化为平面对象而不是字典? 大致与此近似的东西: {“x”:”xvalue”,”y”:”\/Date(1313966045485)\/”} 我试图使用三个不同的系统比较ExpandoObject JSON序列化:.NET BCL JavaScriptSerializer,Newtonsoft JSON.NET和ServiceStack的JSON产品。 我从一个相当简单的动态对象开始。 dynamic test = new ExpandoObject(); test.x = “xvalue”; test.y = DateTime.Now; 对于序列化程序来说,将ExpandoObject视为IDictionary似乎更简单。 BCL和ServiceStack都以这种方式开始,但结果与路径完全不同。 JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); Console.WriteLine(javaScriptSerializer.Serialize(test)); // [{“Key”:”x”,”Value”:”xvalue”},{“Key”:”y”,”Value”:”\/Date(1313966045485)\/”}] Console.WriteLine(ServiceStack.Text.JsonSerializer.SerializeToString(test)); // [“[x, xvalue]”,”[y, 8/21/2011 16:59:34 PM]”] 我更喜欢将ExpandoObject序列化更多,因为它是在代码中组装的,就像典型的类会被序列化一样。 您可以为IDictionary的BCL系统添加覆盖JavaScript序列化程序 。 这很好用,假设一个实际上没有IDictionary需要保持这种方式(我还没有)。 JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); javaScriptSerializer.RegisterConverters(new JavaScriptConverter[] { new ExpandoJsonConverter() }); Console.WriteLine(javaScriptSerializer.Serialize(test)); // […]

检查SignalR属性中的授权

我在ServiceStack上有一些服务,并在这个项目中使用SignalR。 现在,我想保护集线器连接(仅对经过身份validation的用户进行访问),但我使用ServiceStack框架身份validation..(不是asp.net身份validation)和ServiceStack的会话(在此会话中写入AuthUserId和身份validation标志)。 因此,当用户尝试连接到集线器时 – 集线器必须检查身份validation… (是的,我可以从Hub请求Cookie(例如,OnConnected方法),但在Authorize Attribute中检查身份validation – 我必须在此类(不在集线器中)中执行此操作 ( http://www.asp.net/signalr/overview/signalr-20/security/hub-authorization ) 所以,我创建了课程 [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public class AuthorizeMyAttribute : AuthorizeAttribute { protected override bool UserAuthorized(System.Security.Principal.IPrincipal user) { //… how can i request Cookies? / or may be can access for ServiceStack session… // and return true or false } } […]

服务堆栈上的SSL

Mono上的服务栈是否支持SSL? 我只能访问一个mac,我在这里找到的指令要求你使用windows工具创建一个pvk文件: http ://joshua.perina.com/geo/post/using-ssl-https-with-mono- httplistener 该站点作为Linux守护进程托管,使用upstart脚本来保持服务器运行。

ServiceStackvalidation并不总是被激活

所以我试图用RavenDB和ServiceStack构建一个End To End集成测试套件,但是我遇到了一个非常奇怪的问题,即validation不能在某些请求上运行。 这真的很奇怪,我不确定我做错了什么。 我正在使用NCrunch。 有时测试通过,有时它会失败。 希望这是一个简单的解决方案,我正在做的事情。 您可以在http://github.com/khalidabuhakmeh/endtoend上下载整个项目 除了VS2012和NuGet Package Restore之外,您不需要任何其他function。 更新:我决定在NCrunch和Resharper Test Runner中运行它,两者都给出相同的结果[见下图]。 更新更新:我认为它可能是XUnit,所以我尝试使用NUnit。 不是仍然是同样的问题。 **另一个更新:根据user1901853的请求输入控制台写入。 这就是结果。“ 最新更新:RequestFilters正在逐渐消失,我不知道为什么。 看起来它可能是一个线程问题,但我看不到在哪里。 我的AppHost正在使用AppHostListenerBase。 using EndToEnd.Core; using Funq; using Raven.Client; using ServiceStack.ServiceInterface.Validation; using ServiceStack.WebHost.Endpoints; namespace EndToEnd { public class TestAppHost : AppHostHttpListenerBase { private readonly IDocumentStore _documentStore; public TestAppHost(IDocumentStore documentStore) : base(“Test AppHost Api”, typeof(TestAppHost).Assembly) { _documentStore = […]

ServiceStack Razor – 默认文档的“禁止”错误

我正在使用Razor格式引擎创建一个基于ServiceStack的网站。 在我的项目的文件夹根目录中我有“default.cshtml”,但是尝试导航到URL(在localhost上)我收到302重定向到default.cshtml和以下页面: Forbidden Request.HttpMethod: GET Request.PathInfo: /default.cshtml Request.QueryString: Request.RawUrl: /default.cshtml 这是我的Global.asax.cs: public class AppHost : AppHostBase { public AppHost() : base(“OOMS 2.0”, typeof(OOMS.ServiceInterface.OOMSService).Assembly) { } public override void Configure(Container container) { Plugins.Add(new RazorFormat()); Plugins.Add(new RequestLogsFeature()); } } public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { new AppHost().Init(); } } 我的web.config: […]