简体   繁体   English

使用DataContractSerializer序列化从WCF服务收到的响应

[英]Serializing Response received from WCF service with DataContractSerializer

We are trying to capture the request and response to/from WCF services in our log. 我们正在尝试在日志中捕获对WCF服务的请求和响应。

When serializing the response received from WCF service using DataContractSerializer, the serialized response is not containing the properties of the message contract, it just contains namespace information. 当使用DataContractSerializer序列化从WCF服务接收的响应时,序列化的响应不包含消息协定的属性,而仅包含名称空间信息。

But we are able to capture the properties of message contract when we use XML Serializer instead of DataContractSerializer. 但是,当我们使用XML序列化器而不是DataContractSerializer时,我们能够捕获消息协定的属性。 These requires changing our base message contract to have a public properties instead of internal which we dont want to. 这些要求将我们的基本消息合同更改为具有公共属性,而不是我们不希望拥有的内部属性。

Is there anyway to capture the properties of message using DataContractSerializer? 无论如何,有没有使用DataContractSerializer捕获消息的属性?

You can use a Message Inspector for logging the actual request and response in the client as well as the service. 您可以使用Message Inspector在客户端和服务中记录实际的请求和响应。 More details on how to implement one can be found in https://msdn.microsoft.com/en-us/library/aa717047%28v=vs.110%29.aspx , http://cgeers.com/2011/05/10/wcf-message-logging/ and http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx 关于如何实现一个更多细节可以发现https://msdn.microsoft.com/en-us/library/aa717047%28v=vs.110%29.aspxhttp://cgeers.com/2011/05 / 10 / wcf-message-logging /http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM