6

I have a client that is mandating that my required string elements have nillable="false", currently all strings in the wsdl come out will nillable="true", IE:

<xs:element name="username" nillable="true" type="xs:string" />

How can i change the nillable="false" ?!? I will take any suggestions on how to do this? Am I the first person that has run into this?

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
stevenrosscampbell
  • 643
  • 1
  • 11
  • 20
  • Related: http://stackoverflow.com/questions/9039850/wcf-wsdl-nillable-attributes/21266714#21266714. – Steven Jan 21 '14 at 18:54

1 Answers1

1

How is this element defined in your data contract?

If it's not already done, try adding a IsRequired=true clause to the data member attribute:

[DataContract]
class YourDataStructure
{
   ......

   [DataMember(IsRequired=True)]
   string username;

   .....
}

Other than that, I'm not aware of any way to influence the XSD being rendered from your WCF data contract, short of writing your own WsdlExporter extension (which is totally possible - just seems a bit overkill here).

user247702
  • 23,641
  • 15
  • 110
  • 157
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Hi Marc. Thanks for the suggestion. I have tried the IsRequired=True, that only removes the minOccurs="0". – stevenrosscampbell Oct 19 '09 at 17:22
  • @Steven: I was afraid of that :-( – marc_s Oct 19 '09 at 17:26
  • Hi Marc, Good news, I already had the WsdlExporter in my wcf service for flattening out the wsdl, so it was actually quite easy to implement this in the WsdlExporter extension. Thanks for the suggestion, without it I don't think I would have gone down that avenue. (Note: I used http://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx for Walking the XmlSchema, and when the appropriate element was found, I was able to go el.IsNillable=false; and it worked. Thanks again. Steven – stevenrosscampbell Oct 19 '09 at 18:35
  • @stevenrosscampbellless, could you share your WSDLExporter solution with me please? I'm facing a similar issue. I don't have WSDLExporter and I'm currently looking at my possible solutions. I have a number of examples but none dealing with `nillable`s. – DoomerDGR8 Sep 09 '12 at 05:51
  • 2
    This doesn't make the schema element non-nillable - consumers like BCS (SharePoint) will still not understand this schema as having "non-null" values. I *know* this is an *old* answer, but this exact same answer has been asserted in multiple places and it *doesn't* address the fundamental problem with the WCF XSD generation. – user2246674 Jul 18 '13 at 01:19
  • See this answer for a sample WsdlExportExtension that sets nillable to false: http://stackoverflow.com/questions/10602749/setting-nillable-false-with-wcf/23366064#23366064 – Vizu Apr 29 '14 at 13:36