views:

136

answers:

2

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.

A: 

have you check c is not null?

The only other thing i can think of is this statement

new WsdlExporter().ExportContract(c);

maybe the compilier doesn't like it, try this instead

WsdlExporter wsdlImporter = new WsdlExporter()
wsdlImporter.ExportContract(c);

We've had scenarios in the past with wcf and chaining operations and the solution has been to unchain the calls.

Jon
I figured it out. The problem is that XmlSerializerOperationBehavior will throw a null reference exception if XmlSerializerFormatAttribute is not present on the ServiceContract interface itself. Had to reflector the whole thing to figure it out...
Jeff
A: 

I figured it out. The problem is that XmlSerializerOperationBehavior will throw a null reference exception if XmlSerializerFormatAttribute is not present on the ServiceContract interface itself. Had to reflector the whole thing to figure it out...

Jeff