无法使用两个或多个参数调用WCF服务合同

时间:2017-02-13 05:19:57

标签: c# wpf wcf

这是我的WCF合同:

--no-merged

当我尝试从我的WPF应用程序中调用它时:

    [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);

如你所见,我正在调用第一份合同,但是我的第二份合同出错:

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,我该怎么做? 我可以从浏览器调用该合同没有问题。也许与我的配置有关?这是我的WPF应用程序配置:

Wrapped

1 个答案:

答案 0 :(得分:1)

在Visual Studio项目中添加WCF引用时,它不完全支持所有WCF REST方法。我建议打开你的<title> <?php echo !empty(FILE_TITLE) ? FILE_TITLE : 'Some Default Title' ; ?> </title> <?php if (!empty(STYLESHEET_1_HREF)): ?> <link rel="stylesheet" href="<?php echo STYLESHEET_1_HREF ?>"> <?php endif; ?> 文件并找到你的'GetChampsBySport'操作。然后添加以下内容:

Reference.cs

如果您无法添加[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)] ,请在参考文献中添加对WebInvoke扩展名的引用。