Exposing selected operation contracts as ReST causing error Operation 'method name' of contract 'IContract' specifies multiple request body

63 Views Asked by At

Here is the scenario. There is an existing service contract with some methods which are getting consumed by a desktop app. Now need to expose some operation contracts via ReST. But it demands to expose all the methods as ReST. Else there is exception with below text which often comes if the params are wrapped.

Really confusing. Seems like a bug in framework.

Error message -

Operation 'SaveEntitiy' of contract 'IService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.

Operation contract.

[ServiceContract]
public interface IService
{
        [OperationContract] //No need to expose this as ReST
        string SaveEntity(int id,string name);

        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
        string GetData(int value);
}

If we expose the SaveEntity as ReST everthing works. Means the configs are correct.

1

There are 1 best solutions below

1
Sumit Saini On

As you are trying to use GET just go with WebGet method like below:

[WebGet(UriTemplate = “GetData/input/{value}”)]

Or

You may also try using [WebGet] alone.