Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在服务引用中将XML反序列化为DTO_C#_Wcf_Serialization - Fatal编程技术网

C# 在服务引用中将XML反序列化为DTO

C# 在服务引用中将XML反序列化为DTO,c#,wcf,serialization,C#,Wcf,Serialization,我想使用捕获的SOAP响应作为测试数据。我已经成功地获得了soapxml,现在想使用它在我的项目服务引用中填充dto。这就是我要摆脱困境的地方 当我将Message.CreateMessage与Message.GetBody或TypedMessageConverter一起使用时,我遇到了一个问题,反序列化程序试图填充PropertyChanged事件处理程序并引发异常。它为什么会这样做?我如何才能阻止它 从评论中添加 截断的XML: <GetServiceDetailsResponse x

我想使用捕获的SOAP响应作为测试数据。我已经成功地获得了soapxml,现在想使用它在我的项目服务引用中填充dto。这就是我要摆脱困境的地方

当我将
Message.CreateMessage
Message.GetBody
TypedMessageConverter
一起使用时,我遇到了一个问题,反序列化程序试图填充
PropertyChanged
事件处理程序并引发异常。它为什么会这样做?我如何才能阻止它

从评论中添加

截断的XML:

<GetServiceDetailsResponse xmlns="http://thing.com/thing/"> 
  <GetServiceDetailsResult xmlns:lt4="http://thing.com/thing/types"> 
    <lt4:generatedAt>2016-10-14T14:10:39.7718069+01:00</lt4:gene‌​ratedAt> 
  </GetServiceDetailsResult> 
</GetServiceDetailsResponse>

2016-10-14T14:10:39.7718069+01:00
代码:

string action=null;
XmlReader bodyReader=XmlReader.Create(新的StringReader(参考资料,例如xml));
Message msg=Message.CreateMessage(MessageVersion.Default,action,bodyReader);
var b=msg.GetBody()`
例外

SetUp:System.TypeInitializationException:的类型初始值设定项 “IntegrationTests.GetServiceDetail.Class1”引发了异常。--> System.ServiceModel.Dispatcher.NetDispatcherFaultException: 格式化程序在尝试反序列化消息时引发异常: 尝试反序列化参数时出错 . 内部异常 消息是命名空间中的“EndElement”“GetServiceDetailsResult” 不应为“”。期望元素 “属性已更改。”


你能举例说明吗?所以,我有(截断的)xml:所以,我有(截断的)xml:
2016-10-14T14:10:39.7718069+01:00
代码片段是:`string action=null;XmlReader bodyReader=XmlReader.Create(新的StringReader(参考资料,例如xml));Message msg=Message.CreateMessage(MessageVersion.Default,action,bodyReader);var b=msg.GetBody()`然后我得到异常:
SetUp:System.TypeInitializationException:“IntegrationTests.GetServiceDetail.Class1”的类型初始值设定项引发了异常。--->System.ServiceModel.Dispatcher.NetDispatcherFaultException:格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数时出错http://thing.com/thing/:GetServiceDetailsResult. InnerException消息是“EndElement”“GetServiceDetailsResult”“来自命名空间”http://thing.com/thing/”他说。应为元素“PropertyChanged.”。
可以用示例详细说明吗?因此,我有(截断的)xml:so,我有(截断的)xml:
2016-10-14T14:10:39.7718069+01:00
代码段是:`string action=null;XmlReader bodyReader=XmlReader.Create(新的StringReader(参考资料,例如xml));Message msg=Message.CreateMessage(MessageVersion.Default,action,bodyReader);var b=msg.GetBody()`然后我得到异常:
SetUp:System.TypeInitializationException:“IntegrationTests.GetServiceDetail.Class1”的类型初始值设定项引发了异常。--->System.ServiceModel.Dispatcher.NetDispatcherFaultException:格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数时出错http://thing.com/thing/:GetServiceDetailsResult. InnerException消息是“EndElement”“GetServiceDetailsResult”“来自命名空间”http://thing.com/thing/”他说。应为元素“PropertyChanged”。
string action = null; 
XmlReader bodyReader = XmlReader.Create(new StringReader(Resources.eg_xml)); 
Message msg = Message.CreateMessage(MessageVersion.Default, action, bodyReader); 
var b = msg.GetBody<GetServiceDetailsResponse>();`