There is an approach, but I think that this will require an additional DataContract, but still there is no need for separate contracts for operations and data for different types of devices. This may be a classic implementation for run-time polymorphism. I just give an idea:
Let's say you have a generic DataContract, for example:
[DataContract] [KnownType(typeof(Extra))] [KnownType(typeof(Extra2))] public class TokenMessage { string tokenValue; string extraValue; [DataMember] public string Token { get { return tokenValue; } set { tokenValue = value; } } }
Other device-specific contracts can inherit TokenMessage as a base class, for example:
[DataContract] public class Extra:TokenMessage { [DataMember] public string Extra { get ;set; } } [DataContract] public class Extra2:TokenMessage { [DataMember] public string Extra2 { get ;set; } }
Now at run time, as you say, you know the argument in the operation contract, which helps us identify the device. Say, based on the type of device, you can create a base class with a derived class, for example:
TokenMessage tm= new Extra();
OR
TokenMessage tm= new Extra2();
So, at run time, you determine which device contract will be part of the genetic response.
Note. Adding KnownType will generate a separate xsd in wsdl for all known types in the base class, but preserves serialization for the data at run time, as this should depend on the actual inheritance chosen.
Pranav singh
source share