开发者

WCF DataContract GetCustomDataToExport

开发者 https://www.devze.com 2023-02-04 00:47 出处:网络
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 w

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 Complex开发者_开发知识库Type 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号