【问题标题】:How to remove or exclude a schema that WCF adds that isn't used?如何删除或排除 WCF 添加的未使用的架构?
【发布时间】:2012-04-24 13:46:32
【问题描述】:

我在 Visual Studio 中使用 WCF 创建了一个 Web 服务,当查看生成的 WSDL 时,它包含对 http://schemas.microsoft.com/2003/10/Serialization 的引用,其中包含许多类型规范。我不使用任何这些规范。有谁知道为什么 WCF 会添加这个以及是否有任何方法可以摆脱它?

在我的服务上使用 singleWsdl 参数时,添加到我的 wsdl 的 xml 如下所示:

<xs:schema xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="anyType" nillable="true" type="xs:anyType" />
  <xs:element name="anyURI" nillable="true" type="xs:anyURI" />
  <xs:element name="base64Binary" nillable="true" type="xs:base64Binary" />
  <xs:element name="boolean" nillable="true" type="xs:boolean" />
  <xs:element name="byte" nillable="true" type="xs:byte" />
  <xs:element name="dateTime" nillable="true" type="xs:dateTime" />
  <xs:element name="decimal" nillable="true" type="xs:decimal" />
  <xs:element name="double" nillable="true" type="xs:double" />
  <xs:element name="float" nillable="true" type="xs:float" />
  <xs:element name="int" nillable="true" type="xs:int" />
  <xs:element name="long" nillable="true" type="xs:long" />
  <xs:element name="QName" nillable="true" type="xs:QName" />
  <xs:element name="short" nillable="true" type="xs:short" />
  <xs:element name="string" nillable="true" type="xs:string" />
  <xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte" />
  <xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt" />
  <xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong" />
  <xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort" />
  <xs:element name="char" nillable="true" type="tns:char" />
  <xs:simpleType name="char">
    <xs:restriction base="xs:int" />
  </xs:simpleType>
  <xs:element name="duration" nillable="true" type="tns:duration" />
  <xs:simpleType name="duration">
    <xs:restriction base="xs:duration">
      <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?" />
      <xs:minInclusive value="-P10675199DT2H48M5.4775808S" />
      <xs:maxInclusive value="P10675199DT2H48M5.4775807S" />
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="guid" nillable="true" type="tns:guid" />
  <xs:simpleType name="guid">
    <xs:restriction base="xs:string">
      <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}" />
    </xs:restriction>
  </xs:simpleType>
  <xs:attribute name="FactoryType" type="xs:QName" />
  <xs:attribute name="Id" type="xs:ID" />
  <xs:attribute name="Ref" type="xs:IDREF" />
</xs:schema>

【问题讨论】:

    标签: wcf wsdl


    【解决方案1】:

    现在可能为时已晚,但我遇到了这个问题并且能够解决它。我想删除它的原因是因为我在 Java 和 RPG 中生成客户端,而 wsdl2javawsdl2rpg 工具会基于该架构生成大而丑陋的数据结构。

    就我而言,这是因为我使用了DataContract 序列化程序,而我正在序列化的一些对象的类型成员没有[DataContract] 属性。为了使多余的模式消失,一切都被序列化,一直到类型树都需要具有该属性。

    只要服务合同上有继承的公共成员,它也会遇到这个问题。

    【讨论】:

    • 总是有兴趣让我的东西变得更好。 :) 检查了我的类和接口,据我所知,所有类都有 [DataContract],所有类成员都有 [DataMember]。这是一个非常简单的合约,所以没有继承。
    • 会不会是我使用了像 int 这样的“奇数”类型?和合同中的 IEnumerable
    • 可能,我们没有任何泛型类型,所以这可能是您的问题。
    • @Markus 很可能根据XmlSerializer Class 文档部分:ArrayList 和通用列表的序列化“XmlSerializer 无法序列化或反序列化以下内容:ArrayList 的数组列表"
    【解决方案2】:

    我同意没有必要删除它。它也被使用了很多次,而您对此一无所知。更改默认 wsdl 生成的方法是实现 IWsdlExportExtension:

    http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iwsdlexportextension.aspx

    【讨论】:

    • 我部分同意可能不需要删除它,但为什么要包含它呢?如果没有其他模式使用它,我猜想 IWsdlExportExtension 是删除它的方法,但希望有一个更好的解决方案。 :)
    【解决方案3】:

    Microsoft 的 WSDL 实现的 XSD 定义导入此命名空间(请参阅 here)。

    为什么要删除它?

    【讨论】:

    • 由于 wsdl 中没有任何东西(或者至少我找不到任何东西)使用模式指定的类型,因此我认为没有任何意义。似乎没有必要包含未使用的信息。
    猜你喜欢
    • 2014-05-05
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多