在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) 我是第一次构建服务堆栈: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 3.9.71.0编译项目时,我在visual studio中出现了以下警告(似乎也影响了最新版本).不知道为什么它之前没有显示,但是在我创建了一个引用我的主项目并且都引用了相同服务堆栈DLL的测试库后它已经开始显示:
警告2发现无法解析的同一依赖程序集的不同版本之间发生冲突.当日志详细程度设置为详细时,这些引用冲突将在构建日志中列出.C:\ Program Files(x86)\ MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets 1635
检查构建日志显示:
10>"ServiceStack.Interfaces,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"和"ServiceStack.Interfaces,Version = 3.9.60.0,Culture = neutral,PublicKeyToken = null"之间存在冲突.10>"ServiceStack.Interfaces,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"被选中,因为它是主要的并且"ServiceStack.Interfaces,Version = 3.9.60.0,Culture = neutral,PublicKeyToken = null"不是.10>依赖于"ServiceStack.Interfaces,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"[C:\ proj\packages\ServiceStack.Common.3.9.71\lib \net35\ServiceStack.Interfaces.dll]的引用] ......
此错误是正确的,因为除了旧版本的ORMLite之外,NuGet中的最新版本似乎引用了旧版本的ServiceStack.Interfaces(http://i.imgur.com/4vw3069.jpg).我已从我的系统中删除了所有以前版本的ServiceStack,因此它不会拾取任何旧的DLL.我的项目只引用了ServiceStack,common,interfaces和text; 我删除了ORM,因为我没有使用它,但将它添加到两个项目都无济于事.
有点不确定我如何解决这个错误,因为Github似乎自3.9.60后没有更新,任何想法?
我使用ServiceStack(版本3.9.44.0)作为Windows服务(所以我没有使用IIS),我既可以将其作为API使用,也可以将其用作服务网页.
但是,当客户端支持压缩时,我无法确定应该如何启用压缩.
我想如果客户端的请求包含Accept-Encoding:gzip,deflate头部,ServiceStack将透明地压缩数据,但我没有Content-Encoding:gzip在返回的响应中看到任何相应的.
所以我有几个相关的问题:
在使用ServiceStack作为独立服务(没有IIS)的上下文中,如何在浏览器接受响应时为响应启用压缩.
在C#客户端的上下文中,我如何确保压缩客户端/服务器之间的通信.
如果我遗失了什么,欢迎任何帮助.
谢谢.
ServiceStack版本3
我非常熟悉https://github.com/ServiceStack/ServiceStack/wiki/New-API,在这个页面上它特别说"所有这些API都有异步等价物,你可以在需要时使用它们."
是否可以使用async等待ServiceStack的新api?
使用异步等待服务器和客户端代码会是什么样的?
[Route("/reqstars")]
public class AllReqstars : IReturn<List<Reqstar>> { }
public class ReqstarsService : Service
{
public List<Reqstar> Any(AllReqstars request)
{
return Db.Select<Reqstar>();
}
}
Run Code Online (Sandbox Code Playgroud)
客户
var client = new JsonServiceClient(BaseUri);
List<Reqstar> response = client.Get(new AllReqstars());
Run Code Online (Sandbox Code Playgroud)
有些人请将这些同步示例转换为异步吗?
有没有办法在Servicestack.Net中覆盖XML DateTime序列化,就像我们可以使用JSON一样:
JsConfig<DateTime>.SerializeFn = date => new DateTime(date.Ticks, DateTimeKind.Local).ToString("dd.MM.yyyy HH:mm:ss");
Run Code Online (Sandbox Code Playgroud)
我想对所有XML DateTimes做同样的事情.
编辑:
我刚刚发现我可以使用以下方法挂钩XML序列化:
this.ContentTypeFilters.Register("application/xml", SerializeXmlToStream, DeserializeXmlFromStream);
public static void SerializeXmlToStream(IRequestContext requestContext, object response, Stream stream)
{
using (var sw = new StreamWriter(stream))
{
sw.Write(response.ToXml());
}
}
Run Code Online (Sandbox Code Playgroud)
这将返回与没有此挂钩相同的XML.如果有人知道如何使用这种或任何其他全球方式将DateTime的序列化更改为自定义格式,请告诉我.
我有WinForm应用程序,我想使用ServiceStack依赖注入机制:
public class AppHost : AppHostBase
{
public AppHost()
: base("MyName", typeof(AppHost).Assembly)
{
}
public override void Configure(Container container)
{
container.RegisterAutoWiredAs<AppApplicationContext, IAppApplicationContext>();
}
}
Run Code Online (Sandbox Code Playgroud)
然后在某个表单类中使用它:
public class SomeClass : AppBaseForm
{
public IAppApplicationContext AppApplicationContext { get; set; }
public SomeClass(IAppApplicationContext appApplicationContext)
{
AppApplicationContext = appApplicationContext;
}
public SomeClass()
{
}
}
Run Code Online (Sandbox Code Playgroud)
但AppApplicationContext总是如此null.在无参数构造函数中,我写道:
AppApplicationContext = AppHostBase.Resolve<IAppApplicationContext>();
Run Code Online (Sandbox Code Playgroud)
然后每件事都行.但这是正确的方法吗?我的意思是IoC不应该自动解决AppApplicationContext?并且WinForm必须具有无参数构造函数.
其余代码:
private static void Main()
{
var appHost = new AppHost();
appHost.Init();
}
public interface IAppApplicationContext
{
}
public class …Run Code Online (Sandbox Code Playgroud) 如何在验证代码中访问ServiceStack.net会话?
public class UserSettingsValidator : AbstractValidator<UserSettingsRequest>
{
public UserSettingsValidator()
{
RuleFor(x => x.UserId)
.SetValidator(new PositiveIntegerValidator())
.SetValidator(new UserAccessValidator(session.UserId)); //<-- I need to pass the UserID from the session here
}
}
Run Code Online (Sandbox Code Playgroud)
在服务实现中,我只是这样做:
var session = base.SessionAs<UserSession>();
Run Code Online (Sandbox Code Playgroud)
但这对我的抽象验证器不起作用.
谢谢!
编辑:这是版本3.9.71.0
我正在ServiceStack 3.9.71上开发服务基础架构(管理面板+ webservices).当我开始开发过程时,没有错误或警告,所有项目都被编译并运行完美.当我尝试在Linux上部署应用程序时出现问题:管理控制面板没有在那里启动(mono fastcgi-server4).
我备份了所有并从解决方案中的所有项目中删除了所有ServiceStack和ServiceStack Razor依赖项,然后重新安装它们.之后,在编译器日志中出现许多错过类型的警告.我试图运行应用程序,但它们会因错误而崩溃.
编译器日志如下所示.我正在使用俄语版本Visual Studio 2012 Express,因此我使用Google Translator翻译了所有消息.
1>------ Rebuilding all files started: Project: App.Common, Configuration: Debug Any CPU ------
1> App.Common -> d:\projects\app\App.Common\bin\Debug\App.Common.dll
2>------ Rebuilding all files started: Project: App.Models, Configuration: Debug Any CPU ------
3>------ Rebuilding all files started: Project: App.Roles, Configuration: Debug Any CPU ------
2> App.Models -> d:\projects\app\App.Models\bin\Debug\App.Models.dll
3> App.Roles -> d:\projects\app\App.Roles\bin\Debug\App.Roles.dll
4>------ Rebuilding all files started: Project: App.ServiceDTO, Configuration: Debug Any CPU …Run Code Online (Sandbox Code Playgroud) 确定 ServiceStack 实例运行的基本 URL 路径的最佳方法是什么?例如,如果我将 ServiceStack 配置为在 web.config 中的“/api”基本 URL 上运行,如何获取字符串“/api”?我想获取此值以便构建任意请求 DTO 的 URL,如 HATEOAS 样式文档。
例如,如果我有一个SomeRequest带有[Route("/someRequest")]属性的请求 DTO,则该请求的完整 URL 将是“/api/someRequest”。扩展ToUrl方法仅返回基本 URL 下面的部分路径:
new SomeRequest().ToUrl() // returns "/someRequest"
Run Code Online (Sandbox Code Playgroud)
我还没有找到任何简单的方法来做到这一点。ServiceStack 似乎没有公开返回“/api”基本路径值的配置属性。在 ServiceStack 4 中可能可以检查 web.config以获取 ServiceStack 处理程序路径,但我无法弄清楚如何使用当前的 SS 3 配置来执行此操作。
该Request.GetAbsolutePath()方法将生成当前请求的完整路径,例如“/api/someRequest”,然后我可以在它和扩展ToUrl()方法之间进行一些字符串比较来确定基本路径,但这似乎也是一个非常脆弱的解决方案。
有没有更好的方法来获取这个基本 URL?
我有自托管服务堆栈服务器.在客户端应用程序中,它是Windows窗体,我想在用户未经过身份验证时显示登录表单.一种方法是尝试发送请求并WebServiceException像AuthTest一样捕获.
我正在寻找@if(Request.IsAuthenticated)(SocialBootstrapApi示例)等效于客户端.
我有一个自托管应用程序,其中设置了许多路由.而不是通过每一个去和改变路线是/api/<route>其中<route>在现有的路线,我在想,如果我可以用前缀每条路线/api的时候,我开始申请?我知道它可以在IIS托管的环境中设置它web.config但我不确定它是否可能在自托管环境中?
我使用ServiceStack版本3.9.71,我找不到"添加"方法.维基上的文档是否已过时?我该怎么办才能让它发挥作用?
public override void Configure(Container container)
{
this.ServiceExceptionHandler.Add((httpReq, request, exception) => {
return DtoUtils.CreateErrorResponse(request, exception);
});
}
Run Code Online (Sandbox Code Playgroud) servicestack-bsd ×13
servicestack ×10
c# ×6
asp.net ×2
async-await ×1
datetime ×1
hateoas ×1
mono ×1
razor ×1
session ×1
validation ×1
web-services ×1