tags:

views:

150

answers:

1

I'm looking for a way to specify that some MessageBodyMember is required, so that the generated schema would have minOccurs=1 instead of minOccurs=0.
I have to manually edit the schema to add it, and it's really a pain.

I read a few articles that say this is not possible, but they are a bit old; perhaps now there's a way or a workaround.

Anybody knows if it's possible?

A: 

I am not aware of any way to do this - the MessageBodyMember attribute has no property or means to specify that it's a required part and thus should have minOccurs=1 in the WSDL.

See the MSDN docs on MessageBodyMember attribute.

If it's really a big problem, you could potentially create your own WSDL exporter class which would override the existing standard one provided by WCF, and that would add this minOccurs=1 attribute to all MessageBodyMember elements. There's quite a few sample on the web on how to modify and tweak the WCF WSDL exporting mechanism.

marc_s
I'll give that a try tomorrow
Juan Manuel
According to this: http://connect.microsoft.com/wcf/feedback/details/378109/messagebodymember-does-generates-minoccurs-0-in-xsd-and-lacks-isrequired-attribute-equivalent-to-datamember it's not possible to do so with messagecontracts
Juan Manuel
"The problem here is that the WSDL exporter does not get called for MessageContracts so this part of the XSD cannot be modified. It seems that MessageContracts were neglected here too."
Juan Manuel