SvcUtil工具生成DataContractAttribute错误的名称属性值 [英] Svcutil generates wrong Name property value in DataContractAttribute

查看:245
本文介绍了SvcUtil工具生成DataContractAttribute错误的名称属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用svcutil.exe的产生从包含在XSD文件中定义一个Customer类:

When I use svcutil.exe to generate a Customer class from the definition contained in the xsd file:

<xs:schema ...>

<xs:element name="customer" type="Customer" nillable="true" />

<xs:complexType name="Customer">
  <xs:sequence>
    <xs:element name="id" type="xs:decimal" minOccurs="0" />
    <xs:element name="first_name" type="xs:string" />
    <xs:element name="last_name" type="xs:string" />
    <xs:element name="phone" type="Phone" minOccurs="0" />
    <xs:element name="email" type="Email" minOccurs="0" />
    <xs:element name="personal_id" type="xs:string" minOccurs="0" />
    <xs:element name="address" type="Address" minOccurs="0" />
    <xs:element name="status" type="CustomerStatus" />
  </xs:sequence>
</xs:complexType>

</xs:schema>



我得到的类的定义如下:

I get the following definition of the class:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Customer", Namespace="http://www.bluewhite.pl/api/1.0")]
public partial class Customer : object, System.Runtime.Serialization.IExtensibleDataObject
{

与具有无效值DataContractAttribute的Name属性: 客户(从大写字母),因为,根据XS的name属性:元素,它应该是:客户(以小写字母开始)

With the Name property of DataContractAttribute having an invalid value: "Customer" (starting with uppercase letter), since, according to name property of the xs:element, it should be: "customer" (starting with lowercase letter).

我开始svcutil.exe的如下:

I start svcutil.exe as follows:

svcutil.exe" *.xsd /t:code /dconly /n:*,Esap.AdtZapisoMessages /o:Messages.cs /tcv:Version35

生成的XML必须包含一个根。元素命名为客户,我问你,为什么svcutil.exe的使得这个误差

The generated xml must contain a root element named "customer", and I ask you, why svcutil.exe makes this error.

推荐答案

SvcUtil工具是完全正确的存在;在类型的名称是客户。发件人:

svcutil is entirely correct there; the name of the type is Customer. From:

<xs:complexType name="Customer">



小写的客户是上下文来使用作为根元素,然而,更多的是一种的xsd / SOAP的事情,而不是简单地涉及在隔离合同类型。需要注意的是SvcUtil工具有兴趣合同类型; 。这是一个不同的工具来XSD.EXE

The lower-case customer is contextual to the usage as a root element, however, that is more an xsd/SOAP thing, and does not relate simply to the contract type in isolation. Note that svcutil is interested in contract types; it is a different tool to xsd.exe.

如果你想匹配特定的XML布局,SvcUtil工具根本就是错误的工具;这对XSD.EXE作业。我期望XSD.EXE将输出所需的 [XmlRoot(客户)]

If you want to match a particular xml layout, svcutil is simply the wrong tool; that is a job for xsd.exe. I would expect that xsd.exe would output the required [XmlRoot("customer")].

我测试它,果然:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute("customer", Namespace="",
          IsNullable=true)]
public partial class Customer {

这篇关于SvcUtil工具生成DataContractAttribute错误的名称属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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