为什么XSD工具和WSDL生成器之间存在差异,输出不一样

时间:2016-03-08 11:18:40

标签: xml web-services xsd

XSD:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://test/qualified/attribute/v1" 
    xmlns:b="http://schemas.microsoft.com/BizTalk/2003" 
    elementFormDefault="qualified" 
    targetNamespace="http://test/qualified/attribute/v1" 
    id="TestQualifiedAttribute" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Test">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" 
                    maxOccurs="1" 
                    fixed="FixedValue1" 
                    name="TestFixedElement">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:maxLength value="255" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
        <xs:element minOccurs="1" 
                    maxOccurs="1" 
                    name="TestElement">
          <xs:simpleType>
            <xs:restriction base="xs:string">
              <xs:maxLength value="50" />
            </xs:restriction>
          </xs:simpleType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

将xsd放在上面我将其注入WSDL文档并使用xsd.exe工具将其转换为类。情况是:

  • WSDL文档在Test inner elements
  • 中输出限定属性(xmlns)
  • 生成的类(使用xsd.exe)输出元素没有限定属性(xmlns),xmlns仅出现在Test元素上

所以现在我不能使用xsd.exe中生成的Test element来序列化由WSDL生成的Test class

如果我正确理解elementFormDefault = qualified,WSDL生成器输出效果很好,xsd.exe做错了...所以如何修复它,我应该修改XSD以正确定义xmlns输出内在元素?

如果需要,我将提供WSDL和xsd.exe生成的类

XSD.exe输出:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://test/qualified/attribute/v1")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://test/qualified/attribute/v1", IsNullable=false)]
public partial class Test {

    private string testFixedElementField;

    private string testElementField;

    public Test() {
        this.testFixedElementField = "FixedValue1";
    }

    /// <remarks/>
    public string TestFixedElement {
        get {
            return this.testFixedElementField;
        }
        set {
            this.testFixedElementField = value;
        }
    }

    /// <remarks/>
    public string TestElement {
        get {
            return this.testElementField;
        }
        set {
            this.testElementField = value;
        }
    }
}

WSDL输出:

/// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1064.2")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://test/qualified/attribute/v1")]
    public partial class Test : object, System.ComponentModel.INotifyPropertyChanged {

        private string testFixedElementField;

        private string testElementField;

        public Test() {
            this.testFixedElementField = "FixedValue1";
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=0)]
        public string TestFixedElement {
            get {
                return this.testFixedElementField;
            }
            set {
                this.testFixedElementField = value;
                this.RaisePropertyChanged("TestFixedElement");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public string TestElement {
            get {
                return this.testElementField;
            }
            set {
                this.testElementField = value;
                this.RaisePropertyChanged("TestElement");
            }
        }

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

0 个答案:

没有答案