Adding Properties to WCF DataContract
I've added a service reference to my WCF webservice which generated all of my datacontract objects. I'm using BasicHttpBinding. Using a partial class, I've made one of these objects inherit from another class that adds some properties to it. Now it throws an error when making a call to the service:
Test method CP.Exg2010.Tests.UnitTest1.TestWCF threw exception: System.ServiceModel.Dispatcher.NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:RunResult. The InnerException message was 'Error in line 1 position 283. 'Element' 'CommandResult' from namespace 'uri://mycomp.corp/line/exg2010' is not expected. Expecting element '_EngineTracingData'.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: Error in line 1 position 283. 'Element' 'CommandResult' from namespace 'uri://mycomp.corp/line/exg2010' is not expected. Expecting element '_EngineTracingData'.
CommandResult
is a property that is part of the WSDL. _EngineTracingData
is the private field used by a property in a base class.
<XmlIgnore()> <SoapIgnore()> <Newtonsoft.Json.JsonIgnore()> _
Private _EngineTracingData As String = String.Empty
<XmlIgnore()> <SoapIgnore()> <Newtonsoft.Json.JsonIgnore()>
Public Property EngineTra开发者_如何学JAVAcingData As String Implements Interfaces.ICPMasterBaseInfo.EngineTracingData
Get
Return Me._EngineTracingData
End Get
Set(ByVal value As String)
Me._EngineTracingData = value
End Set
End Property
I read something about the deserialization happening in alphabetic order, which would explain why _EngineTracingData
is first. But, that field/property shouldn't even be used in deserialization!
Any help would be appreciated!
Ah, I found it!
Adding
<NonSerialized()>
to the private fields in the base class fixed my issue!
精彩评论