使用多个参数反序列化 WCF POST 请求时出错
Error Deserializing WCF POST Request With Multiple Parameters
我在发布这个问题之前进行了搜索,none 个答案对我有帮助
我在 IIS 上托管 WCF Web 服务并在其中成功使用 GET 和 POST。该错误仅在调用具有多个参数
的 POST 网络方法时显示
示例:
**//this fails**
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "test", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
String test(String p, String credential);
**//this works**
[OperationContract]
[WebInvoke(Method = "POST",UriTemplate = "test")]
String test(String p);
后面的代码只是returns一个用于测试的字符串
我收到以下错误:
The server encountered an error processing the request. The exception
message is 'Error in deserializing body of request message for
operation 'test'. The OperationFormatter could not deserialize any
information from the Message because the Message is empty (IsEmpty =
true)
我正在 POSTMAN
上测试以下网络方法
传递的参数是随机字符串:
p: tt
credetial: ghdhdj
WCF默认不支持form-data,我们只是在使用Http_Post请求时通过Wrapper元素传递参数。
正如你提到的,我们应该使用下面的代码来包装多个参数。
[OperationContract]
[WebInvoke(BodyStyle =WebMessageBodyStyle.Wrapped)]
string GetData(string value,string value2);
然后我们可以用JSON格式传递参数。
{"value":"ab","value2":"cd"}
截图。
如果问题仍然存在,请随时告诉我。
我在发布这个问题之前进行了搜索,none 个答案对我有帮助
我在 IIS 上托管 WCF Web 服务并在其中成功使用 GET 和 POST。该错误仅在调用具有多个参数
的 POST 网络方法时显示示例:
**//this fails**
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "test", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
String test(String p, String credential);
**//this works**
[OperationContract]
[WebInvoke(Method = "POST",UriTemplate = "test")]
String test(String p);
后面的代码只是returns一个用于测试的字符串
我收到以下错误:
The server encountered an error processing the request. The exception message is 'Error in deserializing body of request message for operation 'test'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true)
我正在 POSTMAN
上测试以下网络方法传递的参数是随机字符串:
p: tt
credetial: ghdhdj
WCF默认不支持form-data,我们只是在使用Http_Post请求时通过Wrapper元素传递参数。
正如你提到的,我们应该使用下面的代码来包装多个参数。
[OperationContract]
[WebInvoke(BodyStyle =WebMessageBodyStyle.Wrapped)]
string GetData(string value,string value2);
然后我们可以用JSON格式传递参数。
{"value":"ab","value2":"cd"}
截图。
如果问题仍然存在,请随时告诉我。