Intercepting the SOAP envelop in an HttpRequest - asp.net

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?

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.

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.

Related

How can I detect Fiddler as a proxy on my server?

Does Fiddler add anything to a request that I can use to detect, on the server, when I am using it as a proxy?
I currently add a header to every request using OnBeforeRequest to show Fiddler is being used as a proxy (but I keep forgetting to do it so I would like a more reliable option).
Someone is bound to ask why ... we are testing a web api and mvc application, and want to perform certain actions when we attach Fiddler. This is the simplest of several options, but it would be nice to not have to remember to add a detectable request header through OnBeforeRequest

fiddlercore to mock responses for testing

I need to simulate web response for web requests during some tests. I was going to use fiddler core for that. So fiddler just acts like a proxy and Im able to set response for every request I like. But I need to run something like console application or standalone application to make fiddler core able to intercept the requests. And I need it to be somehow initialized inside my asp.net mvc test application, so that tester could access these fake data, by just using the urls, without the need to run fiddler or any other applications.
For now I tried to run my fiddler application in Controller action method, but it doesnt intercept anything.
I also tried to add URLMonInterop.SetProxyInProcess("127.0.0.1:"+ myPort, ""), but it doesnt work either.
Is there any way to self host fiddler core app and make it intercept the requests?
UPDATE:
In the end I managed to host fiddler core inside asp.net mvc app. I made initialization in a static method of a static class and it did the trick. Also, for some reason after calling shutdown and then performing initialization again I cant proxify anything. I even cal GC.Collect, nothing helps, but refreshing the host process, in my case IIS express.
As documented, SetProxyInProcess affects URLMon clients only, and .NET doesn't use URLMon for networking.
.NET clients typically pick up the current proxy setting automatically, but if you're running FiddlerCore in a different user account, that's not going to work (and you probably don't want your mocker to be messing with any traffic except your test application). So, instead you should configure your application explicitly to proxy its traffic through your FiddlerCore instance; see http://fiddlerbook.com/fiddler/help/hookup.asp#Q-DOTNET and http://fiddlerbook.com/fiddler/help/hookup.asp#Q-IIS and if your services are local http://fiddlerbook.com/fiddler/help/hookup.asp#Q-LocalTraffic

find which server in a web farm the web method got executed?

This question is a consequence of the following question: determining which server (in a web farm) the asp.net ajax request came from?
The problem is that we commonly use automatically generated proxy classes to communicate with the web method (which may be part of asmx/wcf service). When we receive the response from the web services server, how do we know which server it got processed from?
We receive the response from the server side code which is executing (mostly). When its a script service (which can be called via javascript) its another case altogether.
How can we read the response headers once the web service returns?
Am I constrained to build my own proxy classes to solve this problem?
One way. Its not the best way but it will do until something new comes about. If you have a tool like fiddler/burp, you can inspect the response headers. So we must configure the IIS to set the response headers appropriately.
By default they are configured to output something like X-ASP.NET...a good idea would be to add the server name to that...

How to show soap request xml for a web service call?

I am using a web method of a company's web service.
This web method requires one parameter when calling it:
CompanyOpereations srv = new CompanyOperations();
srv.getCustomerInfo(input);
How can I see my soap request xml when calling this method?
How do you want to see it? If it's inside the code; I don't know. (Un)Fortunately .NET does a pretty good job of hiding it for the developer.
However, if you just want to debug the calls and nothing else: try Fiddler. It will show you the Request/Response (including headers and everything else) for the webservice calls. This is what we use for debugging webservices. But you can use it for everything that uses the HTTP protocol for communication.

Accessing IIS's request handling pipeline to inject a request and get the html response

Is it at all possible to inject a request into IIS for a page, have IIS and ASP.Net handle it as normal, but get the response as html handed back to me programmatically?
Yes, I know that I could connect to port 80 using WebRequest and WebResponse, but that becomes difficult if you are accessing the IIS server from the same physical machine (loopback security controls et al).
Basically, I want to inject the request (eg for http://example.org/MyPage.aspx) between the points at which IIS would normally talk to the browser, and the point at which it would route it to the correct ASP.Net application, and get a response back from IIS between the points at which ASP.Net/IIS applies the httpfilters and hands the html back to the browser.
I'm predominantly working with IIS7 so if there is a solution that works just for IIS7 then thats not an issue.
You could implement a custom HttpModule, which would give you access to the IIS pipeline, including the final response. However, you would still need to initiate a request to IIS to actually kick off processing. Not sure if this would work for you.
From the MSDN documentation:
An HTTP module is an assembly that is
called on every request that is made
to your application. HTTP modules are
called as part of the request pipeline
and have access to life-cycle events
throughout the request. HTTP modules
therefore let you examine incoming
requests and take action based on the
request. They also let you examine the
outgoing response and modify it.
Gave you looked into the WebCkiebt class? You can make the request and get the response HTML.
http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadstring(v=VS.100).aspx

Resources