Runtime add DataContract and DataMember to a dynamic class created using .Net Reflection

I used .Net Reflection. Emit to create a dynamic class and its fields. Now, when I use the generic list of this dynamic class object in a Silverlight-enabled WCF service, this gives me an error on the reference side. The service link does not know about this dynamically created type. This is what I can think of. I'm not sure about that? Does anyone have an idea on how to decorate this dynamically created class with a DataContract and its fields with a DataMember?

+4
source share
2 answers

Even if you add attributes DataContractand DataMembera class created using Reflection.Emit at run time, the contract can not be included in the metadata service and be detected by the client just by adding these attributes as service metadata step is performed by checking the contract parameters and return values, and creating a service description before the service has the ability to execute.

One simple option is to use a weak typed parameter in your service, like XElement or Message directly

IE:

void SomeOperation(XElement parameter);
void SomeOtherOperation(Message message);

IWsdlExportExtension . , , , ( ).

+2

, PropertyBuilder.SetCustomAttribute CustomAttributeBuilder DataMemberAttribute. TypeBuilder.

0

Source: https://habr.com/ru/post/1790080/


All Articles