Wednesday, April 7, 2010

OperationContract with required parameters

OperationContract with required parameters

I'm looking for a way to make method parameters required in an OperationContract without switching to MessageContract. For example, I want to be able to declare a method like the following:

public int Transfer([DataParameter(IsRequired=true)]int SourceAccount, [DataParameter(IsRequired=true)]int TargetAccount, [DataParameter(IsRequired=true)]double Amount);

and have System.ServiceModel.Description.
DataContractSerializerMessageContractExporter.ExportBody method not put minOccurs="0" in the WSDL for the operation.

READ AND LEAVE IT(convert all services to MessageContracts)

My enhancement request is to provide a way to tag parameters in an OperationContract as required without switching all our services to MessageContracts.

I'm afraid manually editing the WSDLs and publishing them at different URL is not maintainable at all and is a lot more prone to errors. I would rather convert all services to MessageContracts but the fact is I'm not going to do that either for now. Right now, I'm thinking of investigating the possibility of inheriting from the System.ServiceModel.Description.DataContractSerializerMessageContractExporter class and overriding the ExportBody method and then plugging in that custom DCSMCE into the WCF pipeline. Unfortunately, while DataContractSerializerMessageContractImporter is public, DataContractSerializerMessageContractExporter is an internal class. So I will probably need to do hacky and evil things using reflection, which I would rather not have done either. :)


No comments:

Post a Comment