代码之家  ›  专栏  ›  技术社区  ›  Erup

使用wcf序列化基元数据时出现问题

  •  0
  • Erup  · 技术社区  · 14 年前

    场景:WCF客户端应用程序,调用Web服务(Java)操作,需要一个复杂对象作为参数。已经得到元数据。

    问题:操作有一些必需字段。其中一个是枚举。在发送的SOAP中,是否没有使用WCF诊断和Windows服务跟踪查看器的上面的字段(生成的元数据)-im:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(TypeName="Consult-Filter", Namespace="http://webserviceX.org/")]
    public partial class ConsFilter : object, System.ComponentModel.INotifyPropertyChanged {
    
        private PersonType customerTypeField;
    

    财产:

    [System.Xml.Serialization.XmlElementAttribute("customer-type", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public PersonType customerType {
            get {
                return this.customerTypeField;
            }
            set {
                this.customerTypeField = value;
                this.RaisePropertyChanged("customerType");
            }
        }
    

    枚举:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
        [System.SerializableAttribute()]
        [System.Xml.Serialization.XmlTypeAttribute(TypeName="Person-Type", Namespace="http://webserviceX.org/")]
        public enum PersonType {
    
            /// <remarks/>
            F,
    
            /// <remarks/>
            J,
        }
    

    操作元数据:

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
    public partial class consultRequest {
    
        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://webserviceX.org/", Order=0)]
        [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
        public ServiceClient.ConsultServiceReference.ConsFilter filter;
    
        public consultRequest() {
        }
    
        public consultRequest(ServiceClient.ConsultServiceReference.ConsFilter filter) {
            this.filter = filter;
        }
    }
    

    跟踪日志:

        <MessageLogTraceRecord>
    <HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
    <Method>POST</Method>
    <QueryString></QueryString>
    <WebHeaders>
    <VsDebuggerCausalityData>data</VsDebuggerCausalityData>
    </WebHeaders>
    </HttpRequest>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"></Action>
    <ActivityId CorrelationId="correlationId" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">activityId</ActivityId>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <filter xmlns="http://webserviceX.org/">
    <product-code xmlns="">116</product-code>
    <customer-doc xmlns="">777777777</customer-doc>
    </filter>
    </s:Body>
    </s:Envelope>
    </MessageLogTraceRecord>
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   John Saunders    14 年前

    使用XML序列化程序序列化具有 minOccurs="0" 在XML模式中,添加了一个附加属性。它被命名为*指定的。在您的例子中,我希望您有一个名为 customerTypeSpecified . 您需要将其设置为 true 无论何时你需要 customerType 送人。

        2
  •  0
  •   Scott Seely    14 年前

    简单问题:如果您正常地实例化对象,并使用xmlserializer将其显式写入控制台或system.diagnostics.writeline,您是否看到相同的行为?