2

我在哪里

我正在尝试将一些 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?

4

1 回答 1

2

See this answer for recommended versioning strategies with ServiceStack.

You can't expose multiple versions of SOAP/WSDL's in ServiceStack, you're encouraged to evolve the same DTO's which means there are no previous type versions to create an older version of the WSDL. You would need to host older versions of ServiceStack project for the auto-generated WSDL to match up with older types.

You could also take a snapshot of a WSDL and host it statically, but whether a new SOAP endpoint accepts a client sending an old SOAP version is up to .NET's WCF Message class doing the parsing. But as SOAP is a brittle format, YMMV.

于 2012-12-05T06:16:42.813 回答