WCF Custom WSDL XmlSerializerOperationBehavior
- by Jeff
Hi,
I have code that builds a custom WCF wsdl on the fly. In one particular scenario, the WSDL exported should use the XmlSerializerOperationBehavior as the IWsdlExportExtension as opposed to the default DataContractSerializerOperationBehavior IWsdlExportExtension.
However, every time I try this from the WSDL generation code, I get a null reference exception from the ExportBody method of the XmlSerializerMessageContractExporter (which is used internally in System.ServiceModel by the XmlSerializerOperationBehavior ExportContract method). I've reflector'd it and I can't see anything obviously wrong. For some reason, .NET also doesn't want to work with source stepping in this scenario...
Simply, the most basic way I can reproduce this is
var c = ContractDescription.GetContract(typeof(IMyService));
foreach (var op in c.Operations)
{
op.Behaviors.Remove(typeof(DataContractSerializerOperationBehavior));
op.Behaviors.Insert(0, new XmlSerializerOperationBehavior(op));
}
new WsdlExporter().ExportContract(c); // throws NullReferenceException
Does anyone have any ideas on this?
Thanks very much.