Is there a way to enforce generating *Specified property in Reference.cs for non-complex type fields in wsdl

Viewed 112

Is there a way to actually enforce generating FooSpecified for non-complex types like strings or integers?

The Web Service I am working with defines all record fields as nillable and minOccurs = 0

      <xsd:complexType name="Constituent">
        <xsd:complexContent mixed="false">
          <xsd:extension base="tns:Record">
            <xsd:sequence>
              <xsd:element minOccurs="0" maxOccurs="1" name="ConsId" nillable="true" type="xsd:nonNegativeInteger" />
              <xsd:element minOccurs="0" maxOccurs="1" name="SiteId" nillable="true" type="xsd:nonNegativeInteger" />
              <xsd:element minOccurs="0" maxOccurs="1" name="PredupStatus" nillable="true" type="xsd:string" />

It also specifies Update method with Record as argument:

      <xsd:element name="Update">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element minOccurs="0" maxOccurs="1" name="PartitionId" nillable="true" type="xsd:nonNegativeInteger" />
            <xsd:element minOccurs="0" maxOccurs="1" name="Force" nillable="true" type="xsd:boolean" />
            <xsd:element minOccurs="1" maxOccurs="unbounded" name="Record" type="ens:Record" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

Constituent Record has nearly 200 elements, which can be null. At the same time, Update method on the server side is programmed to ignore all null values if there are more than 10 of them in the update request.

Reference.cs generated from the file does not contain *Specified properties for strings or integers

/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3062.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:object.soap.convio.com")]
    public partial class Constituent : Record {
        private string consIdField;
        private string siteIdField;
        private string predupStatusField;
        private System.Nullable<AdministratorStatus> adminStatusField;
        private bool adminStatusFieldSpecified;

hich causes XmlSerializer to generate lines for each field:

<q1:ConsId xsi:nil="true"/>
<q1:SiteId xsi:nil="true"/>
<q1:PredupStatus xsi:nil="true"/>
<q1:AdminStatus xsi:nil="true"/>
<q1:ConsName><q1:Title xsi:nil="true"/>
<q1:FirstName>234234</q1:FirstName>
<q1:MiddleName xsi:nil="true"/>
<q1:LastName>412341234</q1:LastName>

Which works fine until I try to blank a field out. At that point the field I am trying to blank out is being send as null and is being ignored by the server because there are more than 10 null fields in the request. To be able to remove unwanted null lines from serialization I need all fields to have *Specified property and send in the request only the field I want to be null. I can add them manually, but it's a lot of work that I need to remember to save somewhere else to avoid being removed when refreshing service reference...

Alternatively, is there a way to enforce generating ShouldSerialize property in Reference.cs?

0 Answers
Related