如何为使用 ServiceStack 开发的服务的 API 指定 "namespace" 和 "conformsto" 属性?

How to specify "namespace" and "conformsto" attribute to APIs for services developed using ServiceStack?

我们目前正在将遗留 Web 服务 (asmx) 转换为使用 ServiceStack 平台开发的 REST API 层。

存在一些具有在 asmx 中指定的命名空间和 Binding ConformsTo 属性的 Web 服务。以下是一个这样的例子:

[WebService(Namespace = "http://ourcustomsite.com/externalServices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

我们如何在对应的 ServiceStack 中设置它们?

如果您指的是 ServiceStack 的 SOAP Support,它仅支持使用 .NET DataContract 属性更改命名空间,应为您的 DTO(又名 ServiceModel)所在的每个命名空间指定这些属性,例如:

[assembly: ContractNamespace("http://ourcustomsite.com/externalServices",
           ClrNamespace = "MyApp.ServiceModel.Operations")]
[assembly: ContractNamespace("http://ourcustomsite.com/externalServices",
           ClrNamespace = "MyApp.ServiceModel.Types")]

您还需要在以下位置指定自定义命名空间:

SetConfig(new HostConfig {
    WsdlServiceNamespace = "http://ourcustomsite.com/externalServices",
});

ServiceStack 的 SOAP 绑定不可自定义,也不是设计用于符合现有 SOAP 服务的配置文件。 SOAP 客户端需要使用 /soap11/soap12 WSDL 来生成 WCF 服务参考客户端,或者甚至更好的通用 Soap12ServiceClient 可以使用您的服务现有的类型化 DTO 而不是 WSDL 生成的代理。

避免新项目使用 SOAP

SOAP 的使用应该considered legacy and limited to situations where their usage is mandated. Add ServiceStack Reference together with ServiceStack's generic C#/.NET Service Clients offers a much faster, simpler, versatile and resilient alternative to SOAP that can be utilized in a number of different C#/.NET Clients in a number of different languages,并且当它的使用是一个选项时应该是首选解决方案。