我正在编写一个接收事件的 WCF 服务。这是一个商定的标准,所以我必须坚持服务定义,我不控制客户端发送的数据。尽管数据可能会有所不同,但这仍然是一个公认的标准。
这是我的服务中的一种方法:
complexType ErrorEvent(int requestId, complexType returnValue, ref string errorInfo)
客户端在我的函数将操作和返回的 errorInfo 字符串中发送 XML。
我得到的数据是这样的(完整的 SOAP 请求):
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ErrorEvent xmlns="http://blah">
<requestId>1</requestId>
<returnValue>
<returnCode>0</returnCode>
</returnValue>
<errorInfo>
<ErrorMessage>An error message</ErrorMessage>
<DefaultTask><!-- Complex data --></DefaultTask>
<Task><!-- Complex data --></Task>
<Task><!-- Complex data --></Task>
<Task><!-- Complex data --></Task>
<ExtraMessage>hello</ExtraMessage>
<ExtraMessage>world</ExtraMessage>
</errorInfo>
</ErrorEvent>
</s:Body>
</s:Envelope>
但是,当我尝试运行它时,我收到此错误(已编辑):
格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数 errorInfo 时出错。InnerException 消息是“反序列化 System.String 类型的对象时出错。应来自命名空间“”的结束元素“errorInfo”。从命名空间“”中找到元素“ErrorMessage”。
所以我的问题是,有没有什么方法可以在不改变方法签名的情况下实现我想要做的事情?例如向我的服务添加属性等?还是我需要拦截消息?
感谢您的任何指示。