合同的"操作" ‘’指定多个 请求正文参数为 在没有任何包装的情况下序列化 元素.最多一个主体参数 可以在没有包装的情况下序列化 元素.要么把多余的身体移走 参数或设置BodyStyle 属性上的 WebGetAttribute/WebInvokeAttribute至 包好.

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>

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

如果我只指定以下(无参数)约定,服务将正常工作:

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

如果我有需要非字符串参数的方法,我会得到前面列出的异常.

例子:

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

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

try 了很多谷歌搜索,但结果空手而归,感谢您的帮助.

Cheers,

尼克.

推荐答案

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

Json相关问答推荐

在T—SQL中将STR_AGG与JSON_ARRAY结合起来

您可以使用Jolt对JSON执行OR条件吗

如何编写MongoDB查询以返回数组数组

419(未知状态)使用laravel处理PUT请求

规范化JSON数据

NoneType 对象的 Python 类型错误

将带有::text[]的JSON数组转换未按预期工作

将JSON行转换为TSV格式, for each 数组项生成单独的行

在 CodePipeline 中调用 lambda 时传递用户参数

将 JSON 字符串解析为 Kotlin Android 中的对象列表(MOSHI?)

用powershell条件解析json文件的数组对象

ORA-01422: 精确提取返回的行数超过了与 json 对象组合的请求数

JSON 字段的多个名称

SwiftUI:如何使用 0 索引数组键为 JSON 添加类型

如何从Typescript 中的json响应中获取日期对象

Spring MVC控制器中的JSON参数

通过 JSON 发送 HTML 代码

Protocol Buffer vs Json - 何时 Select 一个而不是另一个

设置对象不是 JSON 可序列化的

将多个值存储在json中的单个键中