WCF webHttpBinding error with method parameters. "At most one body parameter can be serialized without wrapper elements" WCF webHttpBinding error with method parameters. "At most one body parameter can be serialized without wrapper elements" json json

WCF webHttpBinding error with method parameters. "At most one body parameter can be serialized without wrapper elements"


Have you tried setting the WebInvokeAttribute.BodyStyle to Wrapped as the error recommends?


The problem is that your UriTemplate must specify all the values being passed in except for one. It is fine to have complex types other than strings as parameters, we frequently send lightweight json objects to our services and they come in just fine. Here is an example using your last example.

[OperationContract][WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "logout")]GenericApiResult<bool> Logout(Guid SessionKey);

Would work because there is only one parameter being passed in, and it is expected to be in the post body because it is not passed in as a URL parameter, but you can only pass in one body parameter (a parameter passed in the body of the post, not the URL).

You could change your first method like this

[OperationContract][WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "login/{UserName}")]LoginApiResult Login(String UserName, String Password);

and it would work, but Password would come in the post body. The best way in this particular example is to do what you did for the second example like so

[OperationContract][WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "login/{UserName}/{Password}")]LoginApiResult Login(String UserName, String Password);

Does that make sense? Basically all values passed in need to be represented as a URL parameter, except for one that can be passed in the post body. If you need multiple values passed in the post body, make a lightweight object that has the multiple values you need and accept that whole object in the post body.


WCF doesn't support more than one parameter with bare body, if you need pass several parameters in one post method operation, then we need set the BodyStyle to Wrapped.

So in your case you'd have to change your operation contract to the following:

[WebInvoke(Method = "POST", UriTemplate = "evals", BodyStyle = WebMessageBodyStyle.WrappedRequest)][OperationContract]void SubmitVideoPOST(Video videoArg, string userId);

Source: Click Here