从Visual Studio中忽略WSDL时间格式 [英] WSDL time format is ignored from Visual Studio

查看:148
本文介绍了从Visual Studio中忽略WSDL时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自客户的WSDL文件使用以下语法指定时间数据类型:<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>

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>

我在Visual Studio C#项目中将WSDL文件包含为"Web参考"(不是服务参考).会生成以下代码:

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

}

问题在于,在生成的有效负载中,来自WSDL文件([0-9] {2}:[0-9] {2}:[0-9] {2})的模式被完全忽略. IE.有效负载如下:

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> 

代替:

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

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

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

推荐答案

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

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

现在转到自动生成的属性并添加XmlIgnore:

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

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

这篇关于从Visual Studio中忽略WSDL时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆