I've got this interface, from a WCF service:
[ServiceContract]
[ServiceKnownType("GetKnownTypes", typeof(KnownTypesProvider))]
public interface IQuerySageService
{
[OperationContract]
CustomerLedger GetBillingContact(string crmAccountNumber);
[OperationContract]
ImportCrmInvoicesResponse ImportCrmInvoices(List<New.Xrm.Entities.Invoice> invoices);
}
And the method refered above is from this class:
internal static class KnownTypesProvider
{
public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
{
List<Type> types = new List<Type>();
types.Add(typeof(New.Xrm.Entities.InvoiceDetail));
return types;
}
}
But when invoking ImportCrmInvoices
(Invoice
has InvoiceDetail
children) from the client (a CRM workflow), I get the following error:
There was an error while trying to serialize parameter http://tempuri.org/:invoices. The InnerException message was 'Type 'New.Xrm.Entities.InvoiceDetail' with data contract name 'InvoiceDetail:http://schemas.datacontract.org/2004/07/New.Xrm.Entities' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details."
I thought this ServiceKnownType
decoration would do the trick from what I've read, but apparently not.
The types (Invoice, InvoiceDetail) are contained within an assembly, refered by both the client and the server (namespace New.Xrm.Entities
)
Now, the physical CS file that holds those types is huge (7MB), and barely editable. So maybe I'm missing a DataContract
decoration somewhere, but I don't want to go in this file to add it.
Any other ways to achieve this ?