Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am attempting to consume a working .Net 4.5 C# WCF service (RCWindsSvc) via a .Net 4.5 C# MVC4 WebAPI (RCWindsExtSvc). I am receiving the following run-time error when calling the WCF service from the WebAPI:

"Operation 'GetHistory' of contract 'IService1' 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."

I then modified the OperationsContract in the WCF Service as follows:

C#
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
WeatherData[] GetHistory(string table_name, DateTime begin, DateTime end)


In addition, after researching community posts, I modified the generated proxy code (less than ideal) as follows:
C#
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetHistory", ReplyAction="http://tempuri.org/IService1/GetHistoryResponse")]
[System.ServiceModel.Web.WebInvoke(Method = "GET", BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json)]
RCWindsExtSvc.RCWindsSvc.WeatherData[] GetHistory(string table_name, System.DateTime begin, System.DateTime end)

Independently, the WCF Service (RCWindsSvc) functions as expected by accepting multiple parameters and return JSON results when called with a browser. It is only when consuming with the WebAPI do I receive the error.

The community's assistance will be greatly appreciated.
DAFuller
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900