2

I want to look at the XML created in my HttpRequest but can't see how. I've tried looking at the request during runtime but no luck.

I'm working in a .NET 4.0 project (just for context here, not that it matters much starting with 2.0)

I'm making a call to a third party API via my project's service reference:

SomeResponseType response = _apiClient.AddUser(userToAdd);

So how do I capture what AddUser is creating in terms of the raw XML being sent to the host without having to go through the pain of creating an Intercept filter which is not the easiest thing to put together?

PositiveGuy
  • 46,620
  • 110
  • 305
  • 471

2 Answers2

1

You should be able to use Fiddler on your machine to capture the underlying HTTP request.

Alternatively, if you're using WCF, you can enable tracing via your config file. To go this route, see Configuring Message Logging. Then you can use the Service Trace Viewer Tool (SvcTraceViewer.exe) to pretty print your logs.

wsanville
  • 37,158
  • 8
  • 76
  • 101
  • Alright, then go with Fiddler. It shouldn't matter that this is in the context of a unit test, if the third party API is making a HTTP request, then you'll see it (if it's making a local request, there's an extra step to see it in Fiddler). – wsanville Jan 16 '12 at 20:31
  • ok let me open Fiddler. I need to figure out then how Fiddler attaches itself to my request coming from my C# proxy client sending the request. Not sure how to wire fiddler to listen to the stream when I run and debug my code... – PositiveGuy Jan 16 '12 at 20:35
  • You won't need to configure anything, just run Fiddler, then run your unit test. You'll see all HTTP requests made. As a proof of concept, just run Fiddler and then browse the web, you'll see the requests. The only way you'd need to do anything special is if the third party library is making a HTTP request to your local machine. [See here for details](http://stackoverflow.com/questions/214308/how-do-i-get-fiddler-to-stop-ignoring-traffic-to-localhost) if that's the case. – wsanville Jan 16 '12 at 20:38
0

You can use a network sniffing tool such as Fiddler (www.fiddler2.com). Simply fire up Fiddler and then run your app. Fiddler will capture all of the traffic that is going across the wire, and you can look at the XML that is being sent and received from the SOAP service.

Joe Alfano
  • 10,149
  • 6
  • 29
  • 40
  • the problem is, I'm unit testing..this is not a web app running. – PositiveGuy Jan 16 '12 at 20:27
  • I'm not running an app. I'm running code in a C# wrapper project via unit tests and debugging via a Unit Test. So I'm hitting the code that sends the request by debugging via NUnit. – PositiveGuy Jan 16 '12 at 20:36
  • It shouldn't matter. As long as NUnit it kicking off a unit test that is sending traffic over the wire, Fiddler will detect the traffic, and you will be able to see the XML payload that is being sent and received. – Joe Alfano Jan 17 '12 at 03:07