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?

+2


source to share


3 answers


You simply cannot submit a form through WCF; WCF is about state transfer, not implementation. IMO, you would be best served by creating a DTO to represent the data you want to transfer and pass it through WCF.



+2


source


Could you please post the definition of SendMessage.

Also you need to make sure that you update the customer link when you change the contract or service.



EDIT

As noted, you must submit a DTO, you cannot submit a form.

0


source


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.

0


source







All Articles