這是我的WCF合同:無法調用WCF服務合同有兩個或多個參數
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "{type}/sports")]
List<SportsList> GetSportsList(string type);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "{type}/sports/{sport}/championships")]
ChampsCountries GetChampsBySport(string type, string sport);
當我試圖從我的WPF應用程序調用它:
Service1Client client = new Service1Client();
SportsList[] sports = client.GetSportsList("line");
正如你看到的我我打電話給第一份合同,但它給出了關於我的第二份合同的錯誤:
Operation 'GetChampsBySport' 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
。
我已經將BodyStyle
更改爲Wrapped
,我該怎麼辦? 我可以從瀏覽器中調用該合同,沒有任何問題。也許有什麼與我的配置?這是我的WPF應用程序配置:
<client>
<endpoint address="http://localhost:1001/Services/Service1.svc" behaviorConfiguration="webBehavior"
binding="webHttpBinding" contract="MainService.IService1" />
</client>
感謝兄弟,你救了我的一天! –
隨時:)。隨時歡迎。 – firefalcon