I have the following however I am not sure this is the correct way of doing it.
namespace WCFServices
{
[ServiceContract(Name = "IService")]
[ServiceKnownTypeAttribute(typeof(DataItem))]
public interface IService
{
[OperationContract]
void InstantiateThirdParties(string name, IEnumerable<IDataItem> data, IEnumerable<string> modules, IEnumerable<string> states);
}
}
this is the code that uses the interface.
namespace WCFServices
{
public class Service : IService
{
public void InstantiateThirdParties(string name, IEnumerable<IDataItem> data, IEnumerable<string> modules, IEnumerable<string> states)
{
Process.ExecuteAll(name, data, modules, states);
}
}
}
and my only object type at the moment is the following.
namespace DataObjects
{
[Serializable]
[DataContract]
public class DataItem : IDataItem
{
public DataItem();
[DataMember]
public CustomerInfo customer { get; set; }
[DataMember]
public LoanInfo loan { get; set; }
[DataMember]
public DateTime loanProcessingDate { get; set; }
[DataMember]
public string moduleID { get; set; }
[DataMember]
public string processingState { get; set; }
}
}
am I headed in the right direction?
You need to use the KnownTypeAttribute instead of the ServiceKnownTypeAttribute.
If the interface in question is your IDataItem
which is used in the IEnumerable<IDataItem>
parameter then you need to mark the interface itself as a known type:
[KnownTypeAttribute(typeof(IDataItem))]
Check this blog: http://blogs.msdn.com/b/domgreen/archive/2009/04/13/wcf-using-interfaces-in-method-signatures.aspx
Edit: Should be KnownTypeAttribute not ServiceKnownTypeAttribute as papadi pointed out correctly.
Edit 2:
namespace WCFServices
{
[ServiceContract(Name = "IService")]
[ServiceKnownTypeAttribute(typeof(DataItem))]
public interface IService
{
[OperationContract]
void InstantiateThirdParties(string name, IEnumerable<IDataItem> data, IEnumerable<string> modules, IEnumerable<string> states);
}
}
namespace DataObjects
{
[DataContract]
[KnownType(typeof(IDataItem))]
public class DataItem : IDataItem
{
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With