2011-01-14 62 views
1

我想獲取引用我的WCF WSDL的客戶端的默認行爲,以便在導入的DataContracts上將IsReference設置爲true。它看起來像我應該能夠使用與GetCustomDataToExport的IDataContractSurrogate做到這一點......這比較特別意味着添加以下到生成的ComplexType與WSDL關聯的XSD:WCF DataContract GetCustomDataToExport

<xs:attribute ref="ser:Id" /> 
    <xs:attribute ref="ser:Ref" /> 

有,當然沒我可以從MS找到有關如何使用此方法的可用文檔。 MSDN頁面表示它應該返回一個對象...但並不表示這應該是什麼類型的對象....多麼無用...

在我爲此進行反射之前,是否有人那裏知道如何使用這種方法?

謝謝。

回答

4

端起來只是使用IWsdlExportExtension如下:

public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context) 
    { 
     foreach (var complexType in exporter.GeneratedXmlSchemas.Schemas().OfType<XmlSchema>().SelectMany(s => s.SchemaTypes.Values.OfType<XmlSchemaComplexType>()).Where(t => t.QualifiedName.Namespace.StartsWith("http://schemas.datacontract.org/2004/07/"))) 
     { 
      complexType.Attributes.Add(new XmlSchemaAttribute { RefName = new XmlQualifiedName("Id", "http://schemas.microsoft.com/2003/10/Serialization/") }); 
      complexType.Attributes.Add(new XmlSchemaAttribute { RefName = new XmlQualifiedName("Ref", "http://schemas.microsoft.com/2003/10/Serialization/") }); 
     } 
    } 

GetCustomDataToExport在生成WSDL時甚至從來沒有叫。 MS還是很棒的工作。