C# – wsdl.exe-generated WCF service exposing private fields in wsdl

cnetwcfwsdl

I'm doing some wsdl- and client-first development in C# with WCF (the wsdl and client already exist, I'm building the server-side,) and I'm having an odd issue. I used wsdl.exe to generate a contract from my .wsdl, and I'm able to build it and host the WCF service as a Windows service.

However, the wsdl I get from http://localhost/Service?wsdl exposes private fields instead of the public properties (e.g.: instead of OsType I get m_OsTypeField, which is the private variable associated with the public OsType property.)

Here are the attributes for one of the classes having this issue:
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xxxxxxx.com/")]

I'm completely stumped, as the .NET XML serializer is supposed to ignore any private members. Any ideas about why this might be happening?

Best Answer

If you're using WCF, you shouldn't be using wsdl.exe but svcutil.exe instead.

Also, the standard WCF DataContract serializer will happily serialize anything you've marked with a [DataMember] attribute - the .NET visibility setting has no bearing on the SOA view of your data, really.

However, from your code sample it would appear as if you're using the Xml Serializer and not the DataContractSerializer - probably because you used wsdl.exe instead of svcutil.exe.

Can you try to create the server side stubs using svcutil.exe ? Do you still see the same problem?

Marc

Related Topic