1

我正在尝试使用 svcutil 生成的客户端与 RESTful WCF 服务进行通信。

服务合同定义为:

public interface IService1
{
    [OperationContract]
    [WebGet(UriTemplate = "/GetTest?a={a}&b={b}&c={c}")]
    int GetTest(int a, int b, int c);
}

我使用 Visual Studio 引用此服务并使用生成的客户端代码来调用 GetTest 操作。不幸的是,我收到了这条消息:

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

但是当我从 Web 浏览器请求相应的 URL 时,它工作并显示了正确的返回值。

这很奇怪。生成的客户端代码有什么问题吗?还是我配置错误?

以下是我的客户端配置:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="Service1EndPointBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <client>
        <endpoint address="http://localhost:8010/Service1/" behaviorConfiguration="Service1EndPointBehavior"
            binding="webHttpBinding" contract="ServiceReference1.IService1"
            name="Service1EndPoint" />
    </client>
</system.serviceModel>

谢谢。

4

1 回答 1

0

将此属性添加到您的方法中

[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]

解释:

http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webmessagebodystyle.aspx

于 2012-10-11T12:33:38.977 回答