How to debug / trace System.Web.Services.Protocols.SoapHttpClientProtocol.invoke (from Windows mobile)?

I am trying to call a web service from a C # application, but I get an exception:

InvalidOperationException client found response content type of 'text/html; charset=utf-8', but expected 'text/xml' 

How can I see request and response messages without a URL? My service starts on the desktop, but the client works in Windows Mobile CE 6.x, the mobile device connects to Dektop using usb. Probably for this reason, I do not see HTTP traffic in Wireshark or Fiddler (I tried both). The service works - I can check it using Postman (the method returns the correct and meaningful XML result).

+8
debugging c # web-services wireshark tracing
source share
3 answers

You can enable debugging in some libraries that internally make HTTP calls (in my case they are HTTPS, so checking through wirehark is not possible).

You should add to your app.config :

 <system.diagnostics> <trace autoflush="true"/> <sources> <source name="System.Net" tracemode="protocolonly" maxdatasize="1024"> <listeners> <add name="TraceFile"/> </listeners> </source> </sources> <sharedListeners> <add name="TraceFile" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log"/> </sharedListeners> <switches> <add name="System.Net" value="Verbose"/> </switches> </system.diagnostics> 

This will add trace.log where your exe is running. If you do not know where your service works, you can specify a non-relative path.

In addition, it adds the same logs when running code inside Visual Studio in the output window (and not in the output console).

ps: You can change the log level to "Information" if you only need the request and response headers and information about opening and closing the connection (in my example, HTTPS).

+4
source

Well, that will sound weird, but are you using the default document in IIS? I know this is probably not the case, but when I set the default document for my web service site and pointed my ServiceReference to the abbreviated address, it was able to run ... but only locally. Otherwise, I would get the same "HTML instead of XML" error.

The fix in my case was to no longer reference the abbreviated URL in the help desk and type in the full URL (otherwise, not using the default document property for the site.)

+3
source

The easiest and best way to debug a SOAP client is to create a SOAP extension that logs SOAP messages sent from a web service or web service client and vice versa.

Codeproject has a good tutorial on how to do it right: Effective tracing using .NET SOAP extensions

And here is a shorter MSDN article: How to implement the SOAP extension

There are also commercial SOAP debuggers that cost money, such as XML Spy SOAP Debugger or SOAPSonar , which performs validation and invocation.

BTW: If you use PHP or Java, you basically use the same approach.

+2
source

All Articles