wcf : string element nillable=“false”

十年热恋 提交于 2020-01-03 11:15:27

问题


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?


回答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).



来源:https://stackoverflow.com/questions/1589750/wcf-string-element-nillable-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!