c# - ServiceStack - 如何在一项服务中托管多个版本端点?

标签 c# .net wsdl messaging servicestack

我在哪里

我正在尝试将一些 WCF 服务转换为使用 ServiceStack。在大多数情况下,它实现了我想要的,但肯定存在差异。例如,对于 WCF,我有类似的内容:

interface IMethod1{ ResultDTO Method1(InputDTO input); }
interface IMethod2{ ResultDTO Method2(InputDTO input); }
interface IMethod3{ ResultDTO Method3(InputDTO input); }

interface IMyService : IMethod1, IMethod2, IMethod3

然后实现:

public class MyService : ServiceBase, IMyService { /*  ... */ }

我在哪里

使用 ServiceStack,它更像是:

public class Method1{
    // parameters for method as properties
}
public class Method2{
    // parameters for method as properties
}
public class Method3{
    // parameters for method as properties
}

我尝试过各种方法,最近遇到的死胡同是:

public class MyServiceHost<T> : AppHostBase
{
    public MyServiceHost(string version)
        : base("My Service v" + version, typeof(T).Assembly)
    { }

    public override void Configure(Funq.Container container){
        Routes.AddFromAssembly(typeof(T).Assembly);  
    }
}

protected void Application_Start(object sender, EventArgs e) {
    new MyServiceHost<Foo.Bar.V0101.MyService>("1.1").Init();
    new MyServiceHost<Foo.Bar.V0102.MyService>("1.2").Init();            
    new MyServiceHost<Foo.Bar.V0201.MyService>("2.1").Init();            
}

它提示 AppHost 已经初始化。


我想去的地方

我想揭露这样的事情:

http://www.sandwich.com/example/v0101/sandwichservice.wsdl
http://www.sandwich.com/example/v0102/sandwichservice.wsdl
http://www.sandwich.com/example/v0201/sandwichservice.wsdl

http://www.sandwich.com/example/sandwich_v0101.wsdl
http://www.sandwich.com/example/sandwich_v0102.wsdl
http://www.sandwich.com/example/sandwich_v0201.wsdl

最好托管在同一服务进程中。

那么我是否缺少一个简单的答案,或者我对整个事情的处理从根本上是错误的?或者简而言之:使用 ServiceStack,是否可以以及如何在同一主机服务中公开版本化 Web 服务的多个端点和 WSDL?

最佳答案

请参阅 recommended versioning strategies with ServiceStack 的此答案.

您不能在 ServiceStack 中公开 SOAP/WSDL 的多个版本,我们鼓励您发展相同的 DTO,这意味着没有以前的类型版本来创建旧版本的 WSDL。您需要托管旧版本的 ServiceStack 项目,以便自动生成的 WSDL 与旧类型相匹配。

您还可以拍摄 WSDL 的快照并静态托管它,但新的 SOAP 端点是否接受发送旧 SOAP 版本的客户端取决于 .NET 的 WCF Message 类进行解析。但由于 SOAP 是一种脆弱的格式,YMMV。

关于c# - ServiceStack - 如何在一项服务中托管多个版本端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13717028/

相关文章:

java - 使用java下载WSDL文件

Android:关于ksoap2和webservice

java - 本地 WSDL 的 FileNotFoundException

c# - IntPtr 到字节数组并返回

c# - 创建 "Hello World"WebSocket 示例

c# - 用 String[] 填充结构?

.net - 如何反序列化有些不兼容的 BinaryFormatter 数据?

c# - C# 中的事务

.net - 如何找出导致通用 'Application cannot be started. Contact the application vendor.' ClickOnce 错误的原因?

c# - 使用C# Poly框架进行Wcf重试,哪些异常值得重试?