WCF不序列的所有属性 [英] WCF doesn't serialize all properties

查看:343
本文介绍了WCF不序列的所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我消费已导入在VS2010服务引用SOAP服务。我调用由服务提供的服务与一个请求对象中的一个。我遇到的问题是,没有对象的所有属性序列化,或者说不是通过线路发送。请求对象是这样的:

  VAR serviceRequest =新UpdateRequest {
    STOREID = request.StoreId,
    n = request.Id,
    状态=(状态)Enum.Parse(typeof运算(状态),request.myStatus.ToString()),
    参数= request.Parameters,
    validFrom = request.ValidFrom.Value,
    validFromSpecified = request.ValidFromSpecified
};
 

这里是什么是通过网络发送。我已经使用Wireshark捕获它

 < S:信封XMLNS:S =htt​​p://schemas.xmlsoap.org/soap/envelope/>
< S:身体的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema>
< updateStore的xmlns =htt​​p://localhost.service.com/>
    < StoreRequest>
    < STOREID> 1234< / STOREID>
    &其中; validFrom> 2011-11-29T00:00:00&其中; / validFrom>
    <参数>
        <参数1>真< /参数1>
    < /参数>
    < / StoreRequest>
< / updateStore>
< / S:车身>
< / S:信封>
 

两个参数,标识和状态还没有被发送到服务,我只是想不通为什么。这些值被设置和生成的WSDL属性是公开的,具有相同的序列属性作为正在序列的属性

任何帮助将是AP preciated。

编辑---- 更新了服务引用生成code

  ///<备注/>
[系统。codeDom.Compiler.Generated codeAttribute(的System.Xml,4.0.30319.233)
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(code)
[System.Xml.Serialization.XmlTypeAttribute(命名空间=htt​​p://myservice.com/)
公共部分类StoreUpdateRequest:对象,
System.ComponentModel.INotifyPropertyChanged {
    专用长StoreIdField;
    专用长IdField;
    私人布尔IdFieldSpecified;
    私有状态StatusField;
    私人布尔StatusFieldSpecified;
    专用长storeIdField;
    私人布尔storeIdFieldSpecified;
    私人的System.DateTime validFromField;
    私人布尔va​​lidFromFieldSpecified;
    私人的System.DateTime validToField;
    私人布尔va​​lidToFieldSpecified;
    私人technicalParameters parametersField;
    ///<备注/>
    [System.Xml.Serialization.XmlElementAttribute(ORDER = 0)]
    众长STOREID {
        得到 {
            返回this.StoreIdField;
        }
        组 {
            this.StoreIdField =价值;
            this.RaisePropertyChanged(STOREID);
        }
    }

    ///<备注/>
    [System.Xml.Serialization.XmlElementAttribute(ORDER = 1)]
    众长ID为{
        得到 {
            返回this.IdField;
        }
        组 {
            this.IdField =价值;
            this.RaisePropertyChanged(ID);
        }
    }
 

解决方案

问题已解决。错误是,SOAP服务已被更新,一些属性现在在哪里可选。 当一个字段/属性说 XX 标记为可选的SOAP消息WCF创建一个相应的额外的 XXIsSpecified 属性,必须设置为真的:当在 XX 值设置。否则WCF不会序列化,也不发送属性。

有不同的方式,看是否有属性被设置为可选。

  • 在生成的Reference.cs文件中的每个可选都会有相应的IsSpecified属性,就像这样:私人的System.DateTime validFromField; 私人布尔va​​lidFromFieldSpecified;

  • 您可以使用的soapUI ,了解和测试的WSDL

  • 在浏览与Chrome或其他浏览器的WSDL,看看元素的minOccurs属性。如果它的存在,它具有0的值,然后它是可选的。像这样< XS:元素的minOccurs =0NA​​ME =validFrom类型=XS:日期时间/>

I'm consuming a SOAP service that has been imported as a Service Reference in VS2010. I call one of the services with a request object that is provided by the service. The problem I'm having is that not all properties of the object are serialized, or rather not sent over the wire. The request object looks like this:

var serviceRequest = new UpdateRequest{
    StoreId = request.StoreId,
    Id = request.Id,
    Status = (Status)Enum.Parse(typeof(Status), request.myStatus.ToString()),
    parameters = request.Parameters,
    validFrom = request.ValidFrom.Value,
    validFromSpecified = request.ValidFromSpecified
};

And here is what is sent over the wire. I've captured it with wireshark

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<updateStore xmlns="http://localhost.service.com/">
    <StoreRequest>
    <StoreId>1234</StoreId>
    <validFrom>2011-11-29T00:00:00</validFrom>
    <parameters>
        <param1>true</param1>
    </parameters>
    </StoreRequest>
</updateStore>
</s:Body>
</s:Envelope>

Two of the parameters, Id and Status have not been sent to the service, and I just can't figure out why. The values are being set and the WSDL generated properties are public and have the same serialization attributes as the properties that are being serialized.

Any help would be appreciated.

Edit---- Updated with service reference generated code

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://myservice.com/")]
public partial class StoreUpdateRequest : object,        
System.ComponentModel.INotifyPropertyChanged {
    private long StoreIdField;        
    private long IdField;        
    private bool IdFieldSpecified;        
    private Status StatusField;        
    private bool StatusFieldSpecified;        
    private long storeIdField;        
    private bool storeIdFieldSpecified;        
    private System.DateTime validFromField;        
    private bool validFromFieldSpecified;        
    private System.DateTime validToField;        
    private bool validToFieldSpecified;        
    private technicalParameters parametersField;        
    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public long StoreId {
        get {
            return this.StoreIdField;
        }
        set {
            this.StoreIdField = value;
            this.RaisePropertyChanged("StoreId");
        }
    }

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

解决方案

The problem is resolved. The error was that the SOAP service had been updated and some properties now where optional. When a field/property say XX is marked as optional in a SOAP message WCF creates an corresponding extra XXIsSpecified property that must be set to true when the XX value is set. Otherwise WCF will not serialize nor send that property.

There are different ways to see if a property is set as optional.

  • In the generated Reference.cs file each optional will have a corresponding IsSpecified property, like so: private System.DateTime validFromField; private bool validFromFieldSpecified;

  • You can use soapUI to see and test the wsdl

  • Browse to the wsdl with chrome or another browser and see if the element has the minoccurs attribute. If it's there and it has the value of 0 then it's optional. like this <xs:element minOccurs="0" name="validFrom" type="xs:dateTime"/>

这篇关于WCF不序列的所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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