1

A WSDL file from a customer specifies the time data type using this syntax: <xsd:simpleType name="time"><xsd:restriction base="xsd:time"><xsd:pattern value="[0-9]{2}:[0-9]{2}:[0-9]{2}"/></xsd:restriction></xsd:simpleType>

I included the WSDL file as "Web Reference" (not Service Reference) in a Visual Studio C# project. Which generates this code:

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="time")]
public System.DateTime I_TIMETO {
get {
     return this.i_TIMETOField;
}
set {
     this.i_TIMETOField = value;
}

}

The problem is that in the generated payload, the pattern from the WSDL file ([0-9]{2}:[0-9]{2}:[0-9]{2}), is completly ignored. I.e. the payload looks like:

<I_TIMETO xmlns="">17:11:00.0000000+01:00</I_TIMETO> 

instead of:

<I_TIMETO xmlns="">17:11:00</I_TIMETO> 

It is not possible to change the Webservice and I don't want to change the auto generated code.

  • I am not an expert but I am using a WCF service and believe that there is no way to store formatting in a DateTime. All I do is pass the DateTime variable and the service figures it out by itself. On the flipside, if I am passing a string value of DateTime, I need to have a standard format string across client and server. – stripathi Feb 02 '15 at 16:07
  • Sadly it's a SAP webserivce so I can't change the interface. – user3244392 Feb 03 '15 at 11:38

1 Answers1

0

I think there is no good solution, so you have to edit the auto generated code.

Create a partial class of the auto generated code and add a string property with the correct formatting in it:

[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, 
 DataType = "string", ElementName = "I_TIMETO")]
public string I_TIMETO_STR
{
    get
    {
        return this.i_TIMETOField.ToString("HH:mm:ss");
    }
    set
    {
        this.i_TIMETOField = DateTime.ParseExact(value, "HH:mm:ss", CultureInfo.InvariantCulture);
    }
}

Now go to the auto generated property and add a XmlIgnore:

[System.Xml.Serialization.XmlIgnore] 
public System.DateTime I_TIMETO{...