xsd .net soap 响应字段放置在扩展 Any 中而不是定义的 class

xsd .net soap response field placed in extension Any instead of defined class

我有肥皂反应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <ns1:Correlation xmlns:ns1="http://customer.com/contract/vho/header/v1">
      <ns1:ConversationID>0db85463-df83-465d-bd15-5eec0b3ce2ec</ns1:ConversationID>
   </ns1:Correlation>
    <ns1:Source xmlns:ns1="http://customer.com/contract/vho/header/v1">
      <ns1:System>CC</ns1:System>
   </ns1:Source>
    <wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing">http://customer.com/contract/vbs/payment/process-card-payment/v1/establish</wsa:Action>
    <wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing">http://customer.com/contract/vbs/payment/process-card-payment/v1/establish</wsa:MessageID>
    <wsa:RelatesTo xmlns:wsa="http://www.w3.org/2005/08/addressing">8ae6b3d6-b748-43d6-aa1a-6204a934c6de</wsa:RelatesTo>
    <wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
    <tns:ResultStatus xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:vfo="http://customer.com/contract/vfo/fault/v1" xmlns:cmn="http://customer.com/schema/common/v1" xmlns:ns3="http://www.w3.org/2005/08/addressing" xmlns:ns2="http://docs.oasis-open.org/wsrf/bf-2" xmlns:ns1="urn:un:unece:uncefact:documentation:standard:CoreComponentType:2" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://customer.com/contract/vho/header/v1">
      <vfo:Name>1006</vfo:Name>
      <vfo:Message>Invalid ChargeAccountNumber (not found).</vfo:Message>
   </tns:ResultStatus>
  </soapenv:Header>
  <soap-env:Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" />
</soapenv:Envelope>

当 seen/used 来自消费 .Net 代码时,Name 和 Message 位于 ResultStatus 对象的 Any 扩展中。 SOAP服务添加为.net项目的服务引用,使用的相关来源XSD如下:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:cmn="http://customer.com/schema/common/v1" xmlns:tns="http://customer.com/contract/vho/header/v1" xmlns:vfo="http://customer.com/contract/vfo/fault/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://customer.com/contract/vho/header/v1" version="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:import schemaLocation="./Fault.xsd" namespace="http://customer.com/contract/vfo/fault/v1" />
  <xsd:element name="Source" type="tns:SourceType" />
  <xsd:element name="Destination" type="tns:DestinationType" />
  <xsd:element name="Correlation" type="tns:CorrelationType" />
  <xsd:element name="Cache" type="tns:CacheType" />
  <xsd:element name="ServiceDocumentation" type="tns:ServiceDocumentationType" />
  <xsd:element name="ResultStatus" type="vfo:FaultType" />
..cut for brevity
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:ws-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:cmn="http://customer.com/schema/common/v1" xmlns:tns="http://customer.com/contract/vfo/fault/v1" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://customer.com/contract/vfo/fault/v1" version="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:import schemaLocation="./bf-2.xsd" namespace="http://docs.oasis-open.org/wsrf/bf-2" />
  <xsd:import schemaLocation="./Meta.xsd" namespace="http://customer.com/schema/common/v1" />
  <xsd:import schemaLocation="./CodeLists.xsd" namespace="http://customer.com/schema/common/v1" />
  <xsd:element name="Fault" type="tns:FaultType">
  </xsd:element>
  <xsd:complexType name="FaultType">
    <xsd:complexContent mixed="false">
      <xsd:extension base="ws-bf:BaseFaultType">
        <xsd:sequence>
          <xsd:element minOccurs="0" name="Name" type="xsd:normalizedString">
          </xsd:element>
          <xsd:element minOccurs="0" name="Severity" type="cmn:FaultSeverityCodeType">
          </xsd:element>
          <xsd:element minOccurs="0" name="Category" type="cmn:FaultCategoryCodeType">
          </xsd:element>
          <xsd:element minOccurs="0" name="ReasonCode" type="xsd:string">
          </xsd:element>
          <xsd:element minOccurs="0" name="Message" type="xsd:string">
          </xsd:element>
          <xsd:element minOccurs="0" name="Specification">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element maxOccurs="unbounded" name="Characteristic" type="cmn:CharacteristicType">
                </xsd:element>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
          <xsd:element minOccurs="0" name="Failures">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element maxOccurs="unbounded" name="Failure" type="tns:FailureType">
                </xsd:element>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  ...../bf-2.xsd
  
  <?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://docs.oasis-open.org/wsrf/bf-2" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:import schemaLocation="./ws-addr.xsd" namespace="http://www.w3.org/2005/08/addressing" />
  <xsd:import schemaLocation="./xml.xsd" namespace="http://www.w3.org/XML/1998/namespace">
    <xsd:annotation>
      <xsd:documentation>
        Get access to the xml: attribute groups for xml:lang as declared on 'schema'
        and 'documentation' below
      </xsd:documentation>
    </xsd:annotation>
  </xsd:import>
  <xsd:element name="BaseFault" type="wsrf-bf:BaseFaultType" />
  <xsd:complexType name="BaseFaultType">
    <xsd:sequence>
      <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax" />
      <xsd:element name="Timestamp" type="xsd:dateTime" />
      <xsd:element minOccurs="0" name="Originator" type="wsa:EndpointReferenceType" />
      <xsd:element minOccurs="0" name="ErrorCode">
        <xsd:complexType mixed="true">
          <xsd:complexContent mixed="true">
            <xsd:extension base="xsd:anyType">
              <xsd:attribute name="dialect" type="xsd:anyURI" use="required" />
            </xsd:extension>
          </xsd:complexContent>
        </xsd:complexType>
      </xsd:element>
      <xsd:element minOccurs="0" maxOccurs="unbounded" name="Description">
        <xsd:complexType>
          <xsd:simpleContent>
            <xsd:extension base="xsd:string">
              <xsd:attribute ref="xml:lang" use="optional" />
            </xsd:extension>
          </xsd:simpleContent>
        </xsd:complexType>
      </xsd:element>
      <xsd:element minOccurs="0" name="FaultCause">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:any namespace="##other" processContents="lax" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
    <xsd:anyAttribute namespace="##other" processContents="lax" />
  </xsd:complexType>
</xsd:schema>

.Net中生成代理参考代码的相关部分如下:

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class AuthoriseCardPaymentResponse {
        
        [System.ServiceModel.MessageHeaderAttribute(Namespace="http://customer.com/contract/vho/header/v1")]
        public WcfFastBreak.ProcessCardPayment.SourceType Source;
        
        [System.ServiceModel.MessageHeaderAttribute(Namespace="http://customer.com/contract/vho/header/v1")]
        public WcfFastBreak.ProcessCardPayment.DestinationType Destination;
        
        [System.ServiceModel.MessageHeaderAttribute(Namespace="http://customer.com/contract/vho/header/v1")]
        public WcfFastBreak.ProcessCardPayment.CorrelationType Correlation;
        
        [System.ServiceModel.MessageHeaderAttribute(Namespace="http://customer.com/contract/vho/header/v1")]
        public WcfFastBreak.ProcessCardPayment.CacheType Cache;
        
        [System.ServiceModel.MessageHeaderAttribute(Namespace="http://customer.com/contract/vho/header/v1")]
        public WcfFastBreak.ProcessCardPayment.ServiceDocumentationType ServiceDocumentation;
        
        [System.ServiceModel.MessageHeaderAttribute(Namespace="http://customer.com/contract/vho/header/v1")]
        public WcfFastBreak.ProcessCardPayment.FaultType ResultStatus;
        
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://customer.com/schema/vbm/payment/card-payment/v1", Order=0)]
        public WcfFastBreak.ProcessCardPayment.AuthoriseCardPaymentVBMResponseType AuthoriseCardPaymentVBMResponse;
        
        public AuthoriseCardPaymentResponse() {
        }
        
        public AuthoriseCardPaymentResponse(WcfFastBreak.ProcessCardPayment.SourceType Source, WcfFastBreak.ProcessCardPayment.DestinationType Destination, WcfFastBreak.ProcessCardPayment.CorrelationType Correlation, WcfFastBreak.ProcessCardPayment.CacheType Cache, WcfFastBreak.ProcessCardPayment.ServiceDocumentationType ServiceDocumentation, WcfFastBreak.ProcessCardPayment.FaultType ResultStatus, WcfFastBreak.ProcessCardPayment.AuthoriseCardPaymentVBMResponseType AuthoriseCardPaymentVBMResponse) {
            this.Source = Source;
            this.Destination = Destination;
            this.Correlation = Correlation;
            this.Cache = Cache;
            this.ServiceDocumentation = ServiceDocumentation;
            this.ResultStatus = ResultStatus;
            this.AuthoriseCardPaymentVBMResponse = AuthoriseCardPaymentVBMResponse;
        }
    }
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34281")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://customer.com/contract/vfo/fault/v1")]
    public partial class FaultType : BaseFaultType {
        
        private string nameField;
        
        private FaultSeverityCodeType severityField;
        
        private bool severityFieldSpecified;
        
        private FaultCategoryCodeType categoryField;
        
        private bool categoryFieldSpecified;
        
        private string reasonCodeField;
        
        private string messageField;
        
        private CharacteristicType[] specificationField;
        
        private FailureType[] failuresField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(DataType="normalizedString", Order=0)]
        public string Name {
            get {
                return this.nameField;
            }
            set {
                this.nameField = value;
                this.RaisePropertyChanged("Name");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public FaultSeverityCodeType Severity {
            get {
                return this.severityField;
            }
            set {
                this.severityField = value;
                this.RaisePropertyChanged("Severity");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool SeveritySpecified {
            get {
                return this.severityFieldSpecified;
            }
            set {
                this.severityFieldSpecified = value;
                this.RaisePropertyChanged("SeveritySpecified");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=2)]
        public FaultCategoryCodeType Category {
            get {
                return this.categoryField;
            }
            set {
                this.categoryField = value;
                this.RaisePropertyChanged("Category");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool CategorySpecified {
            get {
                return this.categoryFieldSpecified;
            }
            set {
                this.categoryFieldSpecified = value;
                this.RaisePropertyChanged("CategorySpecified");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=3)]
        public string ReasonCode {
            get {
                return this.reasonCodeField;
            }
            set {
                this.reasonCodeField = value;
                this.RaisePropertyChanged("ReasonCode");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=4)]
        public string Message {
            get {
                return this.messageField;
            }
            set {
                this.messageField = value;
                this.RaisePropertyChanged("Message");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order=5)]
        [System.Xml.Serialization.XmlArrayItemAttribute("Characteristic", IsNullable=false)]
        public CharacteristicType[] Specification {
            get {
                return this.specificationField;
            }
            set {
                this.specificationField = value;
                this.RaisePropertyChanged("Specification");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order=6)]
        [System.Xml.Serialization.XmlArrayItemAttribute("Failure", IsNullable=false)]
        public FailureType[] Failures {
            get {
                return this.failuresField;
            }
            set {
                this.failuresField = value;
                this.RaisePropertyChanged("Failures");
            }
        }
    }

    [System.Xml.Serialization.XmlIncludeAttribute(typeof(FaultType))]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34281")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://docs.oasis-open.org/wsrf/bf-2")]
    public partial class BaseFaultType : object, System.ComponentModel.INotifyPropertyChanged {
        
        private System.Xml.XmlElement[] anyField;
        
        private System.DateTime timestampField;
        
        private EndpointReferenceType originatorField;
        
        private BaseFaultTypeErrorCode errorCodeField;
        
        private BaseFaultTypeDescription[] descriptionField;
        
        private System.Xml.XmlElement faultCauseField;
        
        private System.Xml.XmlAttribute[] anyAttrField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
        public System.Xml.XmlElement[] Any {
            get {
                return this.anyField;
            }
            set {
                this.anyField = value;
                this.RaisePropertyChanged("Any");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public System.DateTime Timestamp {
            get {
                return this.timestampField;
            }
            set {
                this.timestampField = value;
                this.RaisePropertyChanged("Timestamp");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=2)]
        public EndpointReferenceType Originator {
            get {
                return this.originatorField;
            }
            set {
                this.originatorField = value;
                this.RaisePropertyChanged("Originator");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=3)]
        public BaseFaultTypeErrorCode ErrorCode {
            get {
                return this.errorCodeField;
            }
            set {
                this.errorCodeField = value;
                this.RaisePropertyChanged("ErrorCode");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Description", Order=4)]
        public BaseFaultTypeDescription[] Description {
            get {
                return this.descriptionField;
            }
            set {
                this.descriptionField = value;
                this.RaisePropertyChanged("Description");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=5)]
        public System.Xml.XmlElement FaultCause {
            get {
                return this.faultCauseField;
            }
            set {
                this.faultCauseField = value;
                this.RaisePropertyChanged("FaultCause");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Xml.XmlAttribute[] AnyAttr {
            get {
                return this.anyAttrField;
            }
            set {
                this.anyAttrField = value;
                this.RaisePropertyChanged("AnyAttr");
            }
        }
        
        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));
            }
        }
    }

所以我的问题是,BaseFaultType 中这一行的 XSD 定义不正确吗? 从 xsd 中删除它并更新服务引用会将字段置于 ResultStatus 的 'correct' 位置,或者 .Net 是否错误地解释了有效的 XSD? :

          <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax" />

XSD 定义说 XSD any with ##other 是 ##other - 来自父元素命名空间以外的任何命名空间的元素都可以存在

BaseFault 类型在设计上存在缺陷,并且从未更正过: https://lists.oasis-open.org/archives/wsrf/200506/msg00060.html