C# 从Visual Studio中忽略WSDL时间格式

C# 从Visual Studio中忽略WSDL时间格式,c#,visual-studio-2013,wsdl,time-format,C#,Visual Studio 2013,Wsdl,Time Format,来自客户的WSDL文件使用以下语法指定时间数据类型: 我在VisualStudioC#项目中将WSDL文件作为“Web引用”(而不是服务引用)包括在内。这将生成以下代码: [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, DataType="time")] public System.DateTime I_TIMETO { get { retur

来自客户的WSDL文件使用以下语法指定时间数据类型:

我在VisualStudioC#项目中将WSDL文件作为“Web引用”(而不是服务引用)包括在内。这将生成以下代码:

[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;
}
}

问题在于,在生成的有效负载中,完全忽略了WSDL文件([0-9]{2}:[0-9]{2}:[0-9]{2})中的模式。 即,有效载荷看起来像:

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

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

无法更改Web服务,我不想更改自动生成的代码。

我认为没有好的解决方案,因此您必须编辑自动生成的代码

创建自动生成代码的分部类,并添加具有正确格式的字符串属性:

[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);
    }
}
现在转到自动生成的属性并添加XmlIgnore:

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

我不是专家,但我使用的是WCF服务,我相信没有办法在DateTime中存储格式。我所做的就是传递DateTime变量,然后服务自行计算出来。另一方面,如果我要传递DateTime的字符串值,我需要在客户端和服务器上使用标准格式的字符串。遗憾的是,这是一个SAP webserivce,所以我无法更改接口。