1

I am referencing an external SOAP service (by external I mean created by another development team) as a service reference in my .NET Service Layer.

I have performed this type of operation many times before and typically the proxy that is generated would contain a class structure with data fields and then <FieldName>FieldSpecified properties to allow selective population of those fields.

This approach works well as it is basically passing information back to another application to update certain fields in its database.

Below is a sample class that has been generated in the past with the desired behavior:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sampleproxyclass.com/updatecustomer")]
public partial class Customer : object, System.ComponentModel.INotifyPropertyChanged {


    private string CustomerName;

    private System.Nullable<System.DateTime> dateOfBirthField;

    private bool dateOfBirthFieldSpecified;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string CustomerName{
        get {
            return this.CustomerName;
        }
        set {
            this.CustomerName= value;
            this.RaisePropertyChanged("CustomerName");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType="date", IsNullable=true, Order=4)]
    public System.Nullable<System.DateTime> dateOfBirth{
        get {
            return this.dateOfBirthField;
        }
        set {
            this.dateOfBirthField= value;
            this.RaisePropertyChanged("dateofBirth");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool dateOfBirthFieldSpecified{
        get {
            return this.dateOfBirthFieldSpecified;
        }
        set {
            this.dateOfBirthFieldSpecified= value;
            this.RaisePropertyChanged("dateOfBirthFieldSpecified");
        }
    }

}

For some reason this latest service will not generate the FieldSpecified properties at all which is causing us a major integration headache. I have no control of the XSD specification or creation but I have been trying to help the team responsible for the XSD to change the definition so that it generates the proxy as above in my sample.

I thought that the key was to add minOccurs="0" to the definition but that has not worked. I also got them to try nillable="true" but again no joy.

So my question is what XSD configuration drives the creation of the FieldSpecified properties when a service reference is added to a .NET project?

I am using VS2013, Framework 4.5.1.

connectedsoftware
  • 6,987
  • 3
  • 28
  • 43
  • What do you use to generate these classes? – Kosala W Nov 16 '15 at 10:53
  • @KosalaW just the standard VS IDE generator - by adding a new Service Reference to my project. – connectedsoftware Nov 16 '15 at 10:54
  • I have come across with this in the past. As far as I can remember this is what I did. I got them to send the xsd to me. Then I used xsd2code to generate my reference classes. Using those references, I hosted my own wcf service. Then I used my wcf service to create a client. I fiddled with the xsd many times until it gave me the client that I wanted. – Kosala W Nov 16 '15 at 11:06

1 Answers1

0

Just to answer your question; according to MSDN, this syntax should give you nullable types.

   <xs:element minOccurs="1" maxOccurs="1" name="NameNullable" nillable="true" type="xs:string" />

Unfortunately this has never been straight forward. I ended up writing my own tools to change VS generated code in the past. You may also have to do something similar.

I just did a search on stackoverflow for similar issues and I found this. Some people have commented saying that they wrote their own tools to handle this kind of issues. There is no easy way out it seems.

Community
  • 1
  • 1
Kosala W
  • 2,133
  • 1
  • 15
  • 20