简体   繁体   中英

WCF DataContract GetCustomDataToExport

I'm trying to get the default behavior for a client referencing my WCF WSDL to set IsReference to true on the imported DataContracts. It looks like I should be able to use an IDataContractSurrogate with GetCustomDataToExport to accomplish this...which specifcally means adding the following to the generated ComplexType in the xsd associated with the WSDL:

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

There is, of course no usable documentation I can find from MS about how to use this method. The MSDN page says it should return an object...but does not indicate at all what type of object this should be....how useless...

Before I go reflector'ing for this, does anyone out there know how to use this method?

Thanks.

Ended up just using an IWsdlExportExtension as follows:

   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 is never even called when the WSDL is generated. Great job, yet again, MS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM