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

3

10

I am trying to call web service from C# application but I am getting exception:

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

How can I see the request and reponse messages un URL? My service runs on Desktop, but client runs on Windows Mobile CE 6.x, mobile device is connected to the Dektop using usb. Probabily that is the reason why I don't see the HTTP traffic in Wireshark or Fiddler (I have tried both). The service works - I can check it using Postman (method returns correct and meaningful result XML).

Upturned answered 14/11, 2016 at 12:29 Comment(2)
A webservice returning html could mean there was an error and hence the server response is an error page instead of xml. It might help if you can log what happened at server.Justino
Maybe you can use your dev-machine as a proxy for the mobile device to enable the use of Fiddler?Incubation
W
7

You can turn on the debug on some of the libraries that internally make the HTTP calls (in my case, they are HTTPS, so inspecting via wireshark is impossible).

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 a trace.log where your exe runs. If you don't know where your service is running, you should be able to put a non-relative path.

Also, this adds the same logs when running the code inside Visual Studio, in the output window (not the output console).

P.S.: You can change the log level to "Information" if you just need the headers of the request and responses and information on opening and closing connection.

Waltz answered 3/8, 2017 at 3:7 Comment(0)
D
3

Okay, this is going to sound weird, but are you using Default Document within IIS? I know this probably shouldn't be the case, but when I set up a default document for my web service's site, and pointed my ServiceReference to the shortened address, it was able to run... but only locally. Otherwise, I'd get that same "Html instead of XML" error.

The fix in my case was to no longer refer to the shortened URL in the service reference, and type out the full URL (aka, not using the default document property for the site.)

Damnatory answered 2/8, 2017 at 19:32 Comment(3)
I think the original question is for printing the in and out of the SOAP messages. Hopefully your answer helps too though!Waltz
Yes - shame on you for trying to help solve this fellow's root problem. That said, you probably should have done this as a comment to his question.Arv
Well, there's a reason I suggested what I did. His question was about debugging an issue... but my comment was what a fix for his issue might be (which might save him some debugging time.) I know that it tripped me up of nearly a day's development time when I ran across it - and like I said, it's the exact same error message I got in extremely similar circumstances (worked locally, worked non-locally to get/update Service Reference, but didn't work non-locally when actually run.) Ehn - if it doesn't help him, there's a good chance it'll help someone else in the future. :-)Damnatory
S
2

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

Codeproject has a good tutorial how to do this properly: Efficient Tracing Using SOAP Extensions in .NET

And here is a shorter MSDN article: How to: Implement a SOAP Extension

There are also commercial SOAP Debuggers out that are worth the money, like the XML Spy SOAP Debugger or SOAPSonar which does validation and invocation.

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

Shifflett answered 5/8, 2017 at 21:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.