Wsdl.exe - generated WCF service opening private fields in wsdl

I am doing wsdl and client-first development in C # with WCF (wsdl and client already exist, I am creating backend) and am having strange problem. I have used wsdl.exe to create a contract from my .wsdl and I can create and host the WCF service as a Windows service.

However, the wsdl obtained from http: // localhost / Service? Wsdl is throwing private fields instead of public properties ( e.g .: instead of OsType

i get m_OsTypeField

, which is a private variable associated with a public property OsType

.)

Here are the attributes for one of the classes having this problem: [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 am completely looped in since the .NET XML serializer has to ignore any private members. Any ideas on why this might be happening?

+2


source to share


2 answers


If you are using WCF you shouldn't be using wsdl.exe

but svcutil.exe

.

In addition, the standard WCF DataContract serializer is happy to serialize whatever you've marked with the [DataMember] attribute - the .NET visibility setting has nothing to do with the SOA representation of your data. Really,

However, from your example code, it looks like you are using the Xml Serializer and not the DataContractSerializer - possibly because you used wsdl.exe instead of svcutil.exe.



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

Mark

+2


source


Your datacontracts are using the XmlSerializer engine, but your OperationContract is using the DataContractSerializer.

Apply XmlSerializerFormatAttribute in Execution Contract

From MSDN http://msdn.microsoft.com/en-us/library/ms732038(v=VS.90).aspx



Sometimes, the DataContractSerializer is not suitable for serializing your types. WCF supports an alternative serialization mechanism, the XmlSerializer, which you can also use to serialize parameters. The XmlSerializer allows you to have more control over the resulting XML through attributes such as the XmlAttributeAttribute. To switch to using the XmlSerializer for a specific operation or for an entire service, apply the XmlSerializerFormatAttribute to the operation or service. For example:

[ServiceContract] 
public interface IAirfareQuoteService
{
    [OperationContract]
    [XmlSerializerFormat]
    float GetAirfare(Itinerary itinerary, DateTime date);
}

      

For more information, see Using the XmlSerializer Class. Remember that manually switching to the XmlSerializer as shown here is not recommended unless you have a specific reason to do so, as described in this thread.

+4


source







All Articles