开发者

Wcf send object from Compact Framewok to Desktop WCF Service properties does not deserialize

开发者 https://www.devze.com 2023-03-04 05:58 出处:网络
I have a wcf service running on a desktop pc. The service has twomethods [System.CodeDom.Compiler.GeneratedCodeAttribute(\"System.ServiceModel\", \"3.0.0.0\")]

I have a wcf service running on a desktop pc. The service has two methods

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

public interface IMainModuleService

{

OrderDTO GetOrderById(i开发者_开发问答nt orderId);

void ProcessOrder(OrderDTO order);

}

I used Necfsvcutil and it generated a proxy and poco's.

When I use GetOrderById(int id) from the compact framework everything works, but when I use ProcessOrder(OrderDTO order) to send an order back to the service although the OrderDTO has all the properties with values, when it arrives on the Desktop service Method, it does not deserialize all the properties of the OrderDTO. OrderDTO.Id==2050 before sending and it arrives as OrderDTO.Id==0. I noticed that every int property value equals zero.

Thank you!


I finally found the problem, netcfsvcutil generates a property with Name PropertyName+Specified for every property in the generated dto. ex.

[System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=20)]
public System.Nullable<int> SalesPersonId
{
    get
    {
        return this.salesPersonIdField;
    }
    set
    {
        this.salesPersonIdField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool SalesPersonIdSpecified
{
    get
    {
        return this.salesPersonIdFieldSpecified;
    }
    set
    {
        this.salesPersonIdFieldSpecified = value;
    }
}

these properties is not part of the entity that is used by the netcfsvcutil to generate the dto. if the propertyNameSpecified does not equal to true the property value is not serialized, So I changed the properties and added a line in the Setter, that checks if the property has a value and sets the value of the propertyNameSpecified to true if it has, like below:

[System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Order=20)]
public System.Nullable SalesPersonId
{
get
{
return this.salesPersonIdField;
}
set
{
this.salesPersonIdField = value;
this.SalesPersonIdSpecified = (value != null);
}
}

0

精彩评论

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

关注公众号