2012-04-24 27 views
8

我用WCF在Visual Studio中創建了一個Web服務,並且在查看生成的WSDL時,它包含對http://schemas.microsoft.com/2003/10/Serialization的引用,其中包含許多類型規範。我不使用任何這些規範。有誰知道爲什麼WCF添加這個,如果有任何方法擺脫它?如何刪除或排除WCF添加的未使用的模式?

的XML添加使用我的服務singleWsdl參數時,我的WSDL看起來像這樣:

<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> 

回答

0

我同意沒有必要刪除它。還有很多次它被使用,你不知道它。更改默認WSDL generatio的方式是通過實施IWsdlExportExtension:

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

+0

我部分同意可能不需要刪除它,但爲什麼要包含它呢? 我猜想,如果沒有其他架構使用它,IWsdlExportExtension是將其刪除的方式,但希望有更好的解決方案。 :) – Markus 2012-04-25 10:57:31

0

微軟的WSDL實現進口的XSD定義這個命名空間(見here)。

爲什麼要刪除它?

+0

因爲wsdl中沒有任何東西(或者至少我找不到任何東西)使用模式指定的類型,所以我沒有看到它在那裏的一個要點。似乎沒有必要包含未使用的信息。 – Markus 2012-04-24 14:48:16

1

也許爲時已晚了,但我遇到了這個問題,並能夠解決它。我想刪除它的原因是因爲我在Java和RPG中都生成了客戶端,並且wsdl2javawsdl2rpg工具基於該架構生成大型,醜陋的數據結構。

在我的情況下,這是因爲我使用的是DataContract序列化器,而我正在序列化的一些對象的成員類型沒有[DataContract]屬性。爲了使這個額外的模式消失,所有的東西都被序列化,直到需要擁有該屬性的類型樹。

無論何時服務合約上存在繼承的公共成員,它也有此問題。

+0

總是有興趣讓我的東西更好。 :) 檢查我的類和接口,並且據我所見,所有類都有[DataContract],並且所有類成員都有[DataMember]。這是一個非常簡單的合同,所以沒有繼承。 – Markus 2012-10-19 06:23:20

+1

難道是我使用像int這樣的「奇怪」類型嗎?和IEnumerable 在合同中? – Markus 2012-10-19 06:47:11

+0

可能,我們沒有任何泛型類型,所以這可能是您的問題。 – 2012-10-19 14:16:09