合同的"操作" ‘’指定多个 请求正文参数为 在没有任何包装的情况下序列化 元素.最多一个主体参数 可以在没有包装的情况下序列化 元素.要么把多余的身体移走 参数或设置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,
尼克.