Search code examples
wcf

Message or a type that has MessageContractAttribute and other parameters of different types


I'm developing WCF services where some classes have the [MessageContract] attribute, and some don't.

When I try to run the services I get this error message below:

The operation 'ProcessOperation' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

Does it mean that all the services must have [MessageContract] although they are not related?


Solution

  • No, it means that you have multiple parameters on the method and some of them are not messages. Try posting the interface to your service.

    This blog post explains:

    ... problem is that message contracts cannot be used at the same time as other parameter types. In this case, the return value of the operation is a string. Return values are just another output parameter, so this operation is mixing a message contract message with a primitive parameter type. This fails because message contracts give you control of the layout of the SOAP message, preventing the system from melding in these additional parameters.

    Important note:

    By the way, the error message you get when you try to mix message contracts looks like this.