WCF serialization error
I have a WCF service method that takes an interface as a parameter called IClient
[OperationContract]
void RegisterClientToCallBackTo(IClientCallBack client);
public interface IClient
{
void SendMessage(string message);
}
I have a window form that implements iclient, and when I submit the form to a method, I get the error:
Type 'FormMain' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute. Consider marking the base type "System.Windows.Forms.Form" with the DataContractAttribute or SerializableAttribute, or removing them from the derived type.
I tried to mark the form with [DataContractAttribute] and [SerializableAttribute] but I still get the same error
any ideas?
The post says that you cannot just mark the subclass (ie your form) with [DataContractAttribute] and [SerializableAttribute], you must mark all parent classes with [DataContractAttribute] and [SerializableAttribute]. You will need to find another way.
It seems odd to pass a form anyway - it doesn't seem like a good encapsulation to have a form of service contact management. Perhaps it's time to take a look at a View Pattern like MVC or MVP ? Then your callback will be in the class under your control.
source to share