【问题标题】:WCF Defining Interface Contract in WSDLWCF 在 WSDL 中定义接口契约
【发布时间】:2012-03-21 16:05:33
【问题描述】:

我正在构建一个概念验证 WCF 服务,并有意构建所有接口,以避免在必要时提供任何具体实现。我想将生成的合同(包括消息定义)发送给另一个团队,以开始针对我正在构建的合同进行构建,但除非我提供一个用 DataContractAttribute 修饰的类,否则消息参数不会被序列化。有没有办法让我继续使用松耦合的接口来定义我的合同,或者我是否需要使用类来构建我的所有消息?

示例服务

[ServiceContract]
public interface ITestService
{
  [OperationContract]
  ITestResponse TestOperation(ITestRequest request);
}

public interface ITestRequest
{
  string Message { get; set; }
}

public interface ITestResponse
{
  bool Success { get; set; }
}

XSD 定义示例

<xs:element name="TestOperation">
  <xs:complexType>
    <xs:sequence>
      <!--I want this to be a reference to a complex type with definition of it's members-->
      <xs:element minOccurs="0" name="result" nillable="true" type="xs:anyType"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

【问题讨论】:

    标签: wcf soap


    【解决方案1】:

    简短的回答是您必须使用实现接口的类型,而不是接口本身。您可能已经发现,您不能在接口上使用 DataContract。

    WCF 序列化程序旨在使用具体类型,因为它必须将它们转换为基于 XML 架构的类型。 XML Schema 没有 .NET 语言中定义的“接口”的概念。 soap 标准使用 XML Schema 描述 WSDL 中的“类型”,因此它们可以被任何用任何语言编写的“知道”如何将 XSD 转换为该语言的适当结构的客户端使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多