开发者

SvcUtil generates "Order" Named Parameter for xsd:all complexcontent

开发者 https://www.devze.com 2023-02-18 16:34 出处:网络
Here is my dilemma, the svcutil command still generates Order Named parameter for complex content who are marked as xsd:all.

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

Here is my sample schema.

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

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.

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.

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

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

Sample Response 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>


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.

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


You can also try this : http://wscfblue.codeplex.com

Works pretty well for me

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号