首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF客户端无法连接到RESTful服务

WCF客户端无法连接到RESTful服务
EN

Stack Overflow用户
提问于 2012-10-11 12:52:16
回答 1查看 428关注 0票数 1

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

服务合同定义为:

代码语言:javascript
复制
public interface IService1
{
    [OperationContract]
    [WebGet(UriTemplate = "/GetTest?a={a}&b={b}&c={c}")]
    int GetTest(int a, int b, int c);
}

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

代码语言:javascript
复制
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时,它工作了,并显示了正确的返回值。

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

以下是我的客户端配置:

代码语言:javascript
复制
<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>

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-10-11 20:33:39

代码语言:javascript
复制
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]

解释:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12832429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档