问题描述
我正在为外部 REST API 创建 WCF 客户端,但收到以下错误:
I'm creating a WCF Client to an External REST API, but are getting the following error:
OperationFormatter 遇到一个无效的消息正文
客户端正确命中服务器并执行我要求的发布",但它期待不同的响应元素,基本上将响应"附加到操作合同名称的名称,例如:
The client hits the server correctly and does the 'Post' that I am requiring, but it is expecting a different response Element, basically appending 'Response' to the name of the OperationContract's Name, such as:
OperationFormatter 遇到一个无效的消息正文.预计会找到带有名称的节点类型元素"'companyResponse' 和命名空间 ''.找到节点类型元素"的名称'公司' 和命名空间 ''
有谁知道如何让它取消在名称中添加响应"的要求?
Does anybody know how to make it remove the requirement for 'Response' to be added to the name?
其他详细信息(我添加了 ReplyAction 但它没有任何区别):
Additional Details (I added ReplyAction but it did not make a difference):
[OperationContract(Name="company", Action = "company", ReplyAction = "company")]
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedResponse,
ResponseFormat = WebMessageFormat.Xml,
UriTemplate = "companies.xml"
)]
Company AddCompany(Company company);
推荐答案
操作合约中的 BodyStyle 已设置为 WrappedResponse.将 BodyStyle 更改为 WebMessageBodyStyle.Bare.
The BodyStyle in the operation contract has been set to WrappedResponse. Change the BodyStyle to WebMessageBodyStyle.Bare.
这告诉 WCF 运行时不要包含包装器,它是一个 XML 节点,Name= MethodName+ 单词Response"
This tells the WCF runtime not to include the wrapper which is an XML node with the Name= MethodName+ the word "Response"
这篇关于OperationFormatter 遇到无效的消息正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!