【问题标题】:How to specify "namespace" and "conformsto" attribute to APIs for services developed using ServiceStack?如何为使用 ServiceStack 开发的服务的 API 指定“命名空间”和“conformsto”属性?
【发布时间】:2018-03-23 05:23:37
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: c# .net servicestack asmx servicestack.redis


    【解决方案1】:

    如果您指的是 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,并且仅限于强制使用它们的情况。 Add ServiceStack Reference 与 ServiceStack 的 generic C#/.NET Service Clients 一起提供了很多 faster, simpler, versatile and resilient 的 SOAP 替代方案,可以在 number of different C#/.NET Clientsnumber of different languages 中使用,并且在可以选择使用时应该是首选解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-08
      • 1970-01-01
      • 2012-03-24
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多