I am having a WCF service. The service is so that it returns the result as string. When I run the application, I am getting this error message.
The operation ‘GetTemplate’ 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.
My corresponding code is like this:
Interface:-
[OperationContract]
[WebGet(
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "GetTemplate/templateid={templateID}"
)]
Message GetTemplate(string templateID);
Implementation:-
public Message GetTemplate(string templateID)
{
string jsonText = TemplateManager.GetJSONTemplate(templateID);
return WebOperationContext.Current.CreateTextResponse(jsonText,
"application/json; charset=utf-8", Encoding.UTF8);
}
When I googled t I got to know that, we can’t use any serializable object as parameter or return type when using Message. I want to accept the templateid as parameter, in order to get the corresponding template. Is there any way to accept a parameter without having this error?
Thanks in advance.
Vipin Menon
The error message basically translates into this: using the Message type is an all or nothing proposition, if you have a Message type output then you must either have a single Message parameter for the operation or no parameter at all. You should read this old but good MSDN article on the using the WCF Message type and what it can do for you. The Message class drops the level of coding abstraction from using standard .NET classes down to the WCF “plumbing” level where you manipulate the soap XML message your operation is receiving and manually create the soap XML message the operation will be sending out.
It’s not clear why you are trying to use Message as a return type but you cannot use it in the manner of your sample code in the question.