SvcUtil 生成“订单"xsd:all complexcontent 的命名参数 [英] SvcUtil generates "Order" Named Parameter for xsd:all complexcontent

查看:28
本文介绍了SvcUtil 生成“订单"xsd:all complexcontent 的命名参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的困境,svcutil 命令仍然为标记为 xsd:all 的复杂内容生成 Order Named 参数.

Here is my dilemma, the svcutil command still generates Order Named parameter for complex content who are marked as xsd:all.

这是我的示例架构.

<xsd:complexType name="SpecialReportEntityRow" >
    <xsd:complexContent>
    <xsd:extension base="list:BaseRowExt">
   <xsd:all>
          <xsd:element name="customerName" type="xsd:string" form="unqualified" minOccurs="0" maxOccurs="1" />
    <xsd:element name="Id" type="xsd:long" form="unqualified" minOccurs="0" maxOccurs="1"  />
          <xsd:element name="certificateType" type="xsd:string" form="unqualified" minOccurs="0" maxOccurs="1" />
          <xsd:element name="certificateValidity" type="xsd:long" form="unqualified" minOccurs="0" maxOccurs="1" />
          <xsd:element name="item" type="xsd:long" form="unqualified" minOccurs="0" maxOccurs="1" />
          <xsd:element name="description" type="xsd:string" form="unqualified" minOccurs="0" maxOccurs="1" />
          <xsd:element name="quantity" type="xsd:long" form="unqualified" minOccurs="0" maxOccurs="1" />
          <xsd:element name="startDate" type="xsd:dateTime" form="unqualified" minOccurs="0" maxOccurs="1" />
          <xsd:element name="endDate" type="xsd:dateTime" form="unqualified" minOccurs="0" maxOccurs="1" />
      </xsd:all>
  </xsd:extension>
    </xsd:complexContent>
 </xsd:complexType> 

对于上述架构,这是生成的代理片段.请注意它在属性中生成订单命名参数.尽管架构包含 xsd:all 内容.

For the above schema, Here is the snippet generated proxy. Please see that it generates Order Named Parameter in the Attribute. Despite the schema contains xsd:all content.

主要问题是服务发送数据的顺序是字母顺序或任何随机顺序,因此模式有 xsd:all 而不是 xsd:sequence.现在在运行时,如果我们有订单命名参数,则对象 SpecialReportEntityRow 将初始化为默认值,而不是使用服务数据.例如.CertificateType 属性初始化为空字符串,CertificateValidaty 初始化为 0,所有属性都初始化为其默认值.运行时没有抛出反序列化错误.

The main problem is that the order in which the service sends that data is alphabetic or any random order, hence the schema has xsd:all instead of xsd:sequence. Now at runtime if we have order named parameter the object SpecialReportEntityRow is initialized to default values not with the service data. E.g. CertificateType property is initialized to empty string, CertificateValidaty intialized to 0, all the properties are getting initialized to their default values. There is no deserialization error thrown at runtime.

如果我通过删除 XmlElementAttribute Order 命名参数来修改代理类,那么在运行时对象 SpecialReportEntityRow 将获得正确的服务数据.

If i modify the proxy class by removing the XmlElementAttribute Order named parameter then at runtime the object SpecialReportEntityRow is getting proper service data.

谁能指导我如何解决这个问题,我不想修改代理类,为什么 svcutil 不考虑 xsd:all.

Could anyone guide me how do i resolve this issue, i do not want to modify the proxy class and why does xsd:all is not considered by svcutil.

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    public string customerName
    {
        get
        {
            return this.customerNameField;
        }
        set
        {
            this.customerNameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
    public long orgId
    {
        get
        {
            return this.orgIdField;
        }
        set
        {
            this.orgIdField = value;
        }
    }

示例响应 XML:

<ns5:rows xsi:type="ns7:SpecialReportEntityRow">
           <certificateType>Dummy Type 1</certificateType>
           <certificateValidity>2</certificateValidity>
           <customerName>Customer1</customerName>
           <description>Revocations by Reason - Unused</description>
           <item>17</item>
        </ns5:rows>
        <ns5:rows xsi:type="ns7:SpecialReportEntityRow">
           <certificateType>Dummy Type 2</certificateType>
           <certificateValidity>2</certificateValidity>
           <customerName>Custome1</customerName>
           <description>Revocations by Reason- Ca Compromise</description>
           <item>19</item>
        </ns5:rows>

推荐答案

据我所知,无法使用 svcutil 抑制Order"属性,因此我们编写了一个 Powershell 脚本来去除它.它很脏,但它有效,我们不必担心在再生时手动将其剥离.

There's no way that I know of to suppress the "Order" attribute with svcutil, so we've written a Powershell script that strips it out. It's dirty, but it works and we don't have to worry about manually stripping it out when we regenerate.

我们使用一个 powershell 脚本来生成我们的代理类,它去除了订单"属性:

We use a powershell script to generate our proxy classes which strips out the "Order" attributes:

svcutil /serializer:XmlSerializer '..\.\Schema\MyService.wsdl' '/n:*,MyService.GeneratedCode'  '/o:MyServiceProxy.cs'  '/nologo' 


(Get-Content .\o:MyServiceProxy.cs) | 
Foreach-Object {
$_ -replace ", ReplyAction=`"\*`"", "" `
       -replace ", Order=.", "" `
       -replace "Order=.", ""
} | 
Set-Content .\o:MyServiceProxy.cs

这篇关于SvcUtil 生成“订单"xsd:all complexcontent 的命名参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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