WCF的WebHttpBinding误差方法参数。 "在大多数一种身体参数可以在不包装元素&QUOT进行序列化; [英] WCF webHttpBinding error with method parameters. "At most one body parameter can be serialized without wrapper elements"

查看:207
本文介绍了WCF的WebHttpBinding误差方法参数。 "在大多数一种身体参数可以在不包装元素&QUOT进行序列化;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作''指定了多个
请求体参数为
系列化没有任何包装
元素。在大多数一种身体参数
可以不封装
的元素序列化。无论是去除多余的体
参数或设置在$ B $的BodyStyle
属性b WebGetAttribute / WebInvokeAttribute裹

Operation '' of contract '' 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.

我想通过以下配置(通过WCF配置编辑器中设置),露出一个C#4.0的WCF服务使用JSON:

I am trying to expose a C# 4.0 WCF Service with JSON via the following config (set via the WCF Config Editor):

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="iPhoneAPI.API">
        <endpoint address="" behaviorConfiguration="NewBehavior0" binding="webHttpBinding"
          bindingConfiguration="" contract="iPhoneAPI.IApi" />
      </service>
    </services>
    <protocolMapping>
      <add scheme="http" binding="webHttpBinding" bindingConfiguration="" />
    </protocolMapping>
    <behaviors>
      <endpointBehaviors>
        <behavior name="NewBehavior0">
          <webHttp defaultOutgoingResponseFormat="Json" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>  
</configuration>

当我访问/API.svc,我得到上面列出的异常信息。

When I access /API.svc, I get the previously listed exception message.

如果我只指定以下(无参数的)合同,服务工作:

If I only specify the following (parameter-less)contract, the service works:

[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "test")]
GenericApiResult<IEnumerable<LiveFeedEntity>> test();

如果我有需要的非字符串参数,我得到上面列出的例外的方法。

If I have methods that require parameters that are non-strings, I get the previously listed exception.

例如:

[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "login")]
LoginApiResult Login(String UserName, String Password);

如果我改变这个功能就像这样:

If I change this function like so:

[OperationContract]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "login/{UserName}/{Password}")]
LoginApiResult Login(String UserName, String Password);



它的工作原理;但是这仅仅是可能的参数类型为String。我如何respolve这对我的其他功能,如:

It works; but this is only possible for parameters of Type String. How do I respolve this for my other functions like:

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "logout")]
GenericApiResult<bool> Logout(Guid SessionKey);



尝试了很多的谷歌搜索,但结果空手而归,任何帮助表示赞赏。

Tried a lot of google searches, but turned up empty handed, any help is appreciated.

干杯,

尼克。

推荐答案

你有没有尝试设置 WebInvokeAttribute.BodyStyle 作为错误建议?

Have you tried setting the WebInvokeAttribute.BodyStyle to Wrapped as the error recommends?

这篇关于WCF的WebHttpBinding误差方法参数。 &QUOT;在大多数一种身体参数可以在不包装元素&QUOT进行序列化;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆