繁体   English   中英

WCF客户端连接到RESTful服务无法正常工作

[英]WCF Client connecting to RESTful service is not working

我正在尝试使用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>

谢谢。

将此属性添加到您的方法

[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]

说明:

http://msdn.microsoft.com/zh-CN/library/system.servicemodel.web.webmessagebodystyle.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM