Does WSDL generated service reference support "required" fields? RRS feed

  • Question

  • My understanding is that a field without "minOccurs=0" in WSDL is a required field. Does the service reference generated from a WSDL file by VS support "required" vs "optional"?  I have been wondering about this for a while.  I checked the generated Reference.cs files and could find any indication.  My feeling is that it is not supported.  Could anyone shed some light on this?


    Friday, April 25, 2014 11:48 AM

All replies

  • please see this related thread.

    hope this helps!

    Friday, April 25, 2014 12:09 PM
  • Thanks for the link. Unfortunately, I am still not clear after reading the thread and linked pages. It appears to indicate this is supported.

    My scenario is slightly different. I generate a service reference from a WSDL file. I access the service by using the reference's proxy classes. When I retrieve data from a service (not sending as discussed in the thread), it seems to me the proxy class accepts data with missing required fields.

    BTW, this WSDL defines a service provided by numerous sources. Some providers strictly follow the WSDL, but some do not.


    Friday, April 25, 2014 12:24 PM
  • Hi,

    DataMemberAttribute.IsRequired Property is used to get or set a value that instructs the serialization engine that the member must be present when reading or deserializing. Data members are exported to the schema as optional elements by default. That is, the minOccurs (XML attribute) value is set to 0. Required data members are exported with minOccurs set to 1. Please check the following MSDN article, it is about Data Member Default Values and mainly focus on the EmitDefaultValue property. And by default, the IsRequired is false. .

    So when in the proxy class, the client accepts data with missing required fields, but when the service updates the DataContract by adding a property with IsRequired = true, without notifying the clients. The clients will send serialized objects that don't include the property, causing an exception to be thrown.

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 28, 2014 2:31 AM
  • Thanks a lot for the elucidation, Amy.  

    I am not clear about the exception mentioned in your post.  I am wondering if you could clarify it a bit.  Let me describe a specific scenario:

    Suppose a WSDL defines a method GetFoo and the response is GetFooResponse that includes a required field foo.  If a client uses the generated proxy class to call GetFoo and gets GetFooResponse, but GetFooResponse does not have the required field foo due a a flawed implementation of the service, would the client get an exception?  

    This is essentially what I was asking. I have the impression such exception is not generated.


    Monday, April 28, 2014 11:10 AM