开发者

WCF proxy client generated with wsdl not matching for ServiceContract, XmlSerializerFormat attributes

开发者 https://www.devze.com 2022-12-11 06:15 出处:网络
I am developing WCF services in .net 3.5 framework and hosting them in IIS 5.1 windows xp sp3 with basicHttpBiding. Services consuming client developed in .net 2.0 fra开发者_StackOverflow中文版mework

I am developing WCF services in .net 3.5 framework and hosting them in IIS 5.1 windows xp sp3 with basicHttpBiding.

Services consuming client developed in .net 2.0 fra开发者_StackOverflow中文版mework. For this I generated proxy client using WSDL.EXE. This tool generates proxy class without any problem, but the problem it adds for every property adds extra property "[property]Specified", but that work fine without any problem, only need to specify "specified = true" when assigning value to any property

To remove this extra property I added XmlSerializerFormat attribe along with ServiceContract attribute. WSDL.EXE generates the class without extra property, but it excludes some class which are included previously.

Is there any properties that I need to set to generate the excluded classes?

Note: All contract classes are attributed with DataContract and properties with DataMemeber.

nRk


XmlSerializer uses XmlIncludeAttribute instead of KnownTypeAttribute to discover child types that are not included in operation contracts. So you might try adding them to the base class:

[XmlInclude(typeof(ChildClass1))]
[XmlInclude(typeof(ChildClass2))]
public class BaseClass {}


The standard WCF DataContractSerializer will serialize everything marked with [DataMember] - regardless of the .NET visibility (public/protected/private/internal).

When you switch to the XmlSerializerFormat, the behavior changes - now the XmlSerializer will serialize everything that has a public visibility, and does not have a [XmlIgnore] marked on it.

I would assume some of your classes and members are not marked with public and thus don't get serialized anymore. Also the XmlSerializer requires classes to have an explicit, parameter-less constructor which will be used in deserialization - do all your classes have that? And of course, that constructor also needs to be public.

0

精彩评论

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

关注公众号