Search code examples
c#xmlweb-serviceswcfsoap

How to figure out exactly where the error is in the deserialization of WCF SOAP XML response?


Apologies if this has been asked before but it seems I cannot find the answer.

I am trying to consume a SOAP Web Service using WCF. I've used Visual Studio 2015's Add Service Reference to add the service reference and generate all code.

The service call fails with the following CommunicationException error:

System.ServiceModel.CommunicationException : Error in deserializing body of reply message for operation 'XYZ'.
---- System.InvalidOperationException : There is an error in XML document (2, 979).
-------- System.FormatException : Input string was not in a correct format.

I understand the error; I understand that something (an element value, probably) in the XML response document cannot be deserialized according to what the svcutil's generated code dictates.

I am logging the XML response document. Also, I am comparing it with the SoapUI response and they both look identical.

SO how can I figure out exactly where the problem is in the XML document? Is there any method, technique or trick to step through the deserialization process and pinpoint the faulty bit? It is a rather long XML document ...

IMHO, at this point the WCF behaves like a black box that I cannot look inside it.

TIA,


Solution

  • Turn on WCF Trace:

    https://learn.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing

    Use the following application to view the results:

    https://learn.microsoft.com/en-us/dotnet/framework/wcf/service-trace-viewer-tool-svctraceviewer-exe