I want to send a put request with some json strings to a server some time in the future. I want to compare the request Im sending to the requirements I have been given, but I do not have access to that server yet so I cant test if the request Im sending is looking the way it should. The only thing I found would be ToString'ing my httpWebRequest (like in this), which is not what I need.
Is there a way to read exactly what I'm sending after (or before) I send it into the void? Or alternatively, is there a way to send a request to myself and read it that way?
Edit: I cannot install foreign software on my workstation. While using a tool like Wireshark probably solves the answer for the general public, I still need a way to do this programmatically.
Edit2: Searching for the topic may have not resulted in anything, but a random topic on the right that SO suggested actually has (almost exactly) what I wanted and all it takes is copy pasting something into the web.config file. Implementing this answer puts (amongst other things) all the connections as well as their contents into the debug console.
Try using an HTTP debugging tool like Fiddler. It acts like a proxy and can let you view the request and response of HTTP requests your program sends.
Here's how to use it with HttpWebRequest: Get HTTP requests and responses made using HttpWebRequest/HttpWebResponse to show in Fiddler
If you aren't allowed to install Fiddler you could think about making your own version of Fiddler in c# to capture traffic How to create a simple proxy in C#?
Related
I'm writing an application using Visual Studio 2010 that needs to communicate with a remote web service. Because the amount of data being submitted is potentially large, (up to 100MB), the service's documentation says that the request message must be sent using GZIP HTTP compression.
My question is how to do that, given that I'm just calling a method on the proxy object that Visual Studio generated, and not actually performing the POST myself? In other words, since there isn't a "request" anywhere in my code to GZIP, how can I tell WCF to do it for me?
I've connected to the service by adding a service reference to my application using the WSDL provided, then invoking a method on the Visual Studio generated proxy to submit the request. An exception is thrown with the message "Request message must be sent using HTTP compression." (This is not unexpected, of course.)
Is there an attribute within the web.config settings that define the WCF service that will cause WCF to GZIP the request before sending it to the remote host?
Note: I've spent significant time searching the web about this, but the problem is that most posts assume that it's the web service's response that needs to be compressed. In my case, however, it's the request that's being sent from my client.
It seems like I have been able resolve this issue in a way that makes no sense to me from a "why does this even exist" way.
First, I was working on the same task as you: trying to use proxy objects to create a web request, and ended up running into the same issue being unable to compress the client object.
The resolution I ended up with was manually creating an XDocument object (XmlDocument would work as well) which has the same structure as the required SOAP XML, and then used the (already) populated proxy object to populate the necessary XML values in the string of SOAP XML.
From there I made a HttpWebRequest object and added the appropriate headers to the request. One of the headers was for compression. Executing the code resulted in getting an entirely different, non-compression related, error.
You can see my solution for the HttpWebRequest here: Compress a HttpWebRequest using gzip
It seems silly that it isn't easy to do through this the proxy object; however, it may be that the third-party did not expose what is necessary in order to add properties to the request header and either a.) they don't know or b.) they don't care, but that's what we have to work with, unfortunately.
I had to figure something out as I am on a deadline, but I hope this helps you out as well.
Have you tried adding <binaryMessageEncoding /> to the <customBinding /> element? I think we are working on similar tasks and I am also receiving the above FaultException. Two other SO topics led me down asking this question. It's something that makes sense, as I'm also not making a WebRequest through the code, but calling the service through the Service Reference created when I imported the WSDL provided by the third-party.
WCF custom binding for compression (a code-based approach)
and
WCF client endpoint compression (a configuration-based approach)
Let me know if you have any success with the above approaches.
Edit
An answer in the following thread indicates that unless you have control over the web service and the client, it might be something that can be done.
Using compression with C# webservice client in Visual Studio 2010
Edit #2
I think a few folks have been able to make progress in compressing a third-party service request using GZip. Please check out this post: Getting error for content mismtach while consuming client web service.
That post helped me get rid of the error message I was receiving (which was telling me that the request must be made using HTTP compression). I hope it helps you as well.
The request message must be sent using HTTP compression (RFC 1952 - GZIP).
I am implementing the client-side of a ms webservice and i would like to see the exact http call that is made. i.e. all the parameters and how they are encoded.
I tried sniffing it with wireshark, but since it seems it is done via https i can see the data.
I am running this client straight out of visual studio. is there a way to see the data there?
Teletic Fiddler is great tool to debug any http communication. http://www.telerik.com/fiddler. I can show request and response information in raw views, xml, JSON etc
It can even inspect https traffic. Follow this guide.
There is a similar question here.
I have this question https://stackoverflow.com/questions/2688464/ajax-request-from-net-give-me-unexpected-results
and i am using tamper data but i am sure firefox is formatting the data in ways i dont understand. Is there a tool i can use to check firefox post request? and perhaps my C# post request?
Recommend you download the Firebug plugin for Firefox, this will allow you to debug on the browser side more easily.
Also take a look at Wireshark (or similar) to inspect the HTTP requests that are actually going out onto the network.
Fiddler is a widely used web proxy/debugger - you can easily see incoming and outgoing requests with it. It can be used with all browsers.
I'm having a strange issue - I saw a similar post on this forum, but it didn't have an answer.
Long story short, I am sending an HttpWebRequest using C# to a web service (stubs were created by adding a web reference in Visual Studio 2008, .NET 2.0) which breaks with the following message: "Unable to parse the incoming request". This is a java based webservice running on weblogic.
Here is the strange part, if I have fiddler running to monitor my request - IT WORKS FINE!!??
My theory is that fiddler is reformatting the request in some manner which the server likes?
Does anyone know what .NET could be doing to the request which fiddler could be fixing?
If not, is there a way I can view my XML programmatically without using fiddler?
Caveat - I do not have access to make changes to the server hosting the web service.
Thanks,
Steve
UPDATE - When I remove the "Decrypt HTTPS traffic" option in fiddler it no longer works. So whatever fiddler is doing to decrypt the HTTPS traffic is what is making this work....
Use Wireshark to see what's going on at the network packet level - that's as definitive as it gets!
(One caveat, which I think is true for Steve but might not be for other readers: this assumes your web service is on a different machine, so that there is some physical network activity to monitor - Wireshark won't help if it's all running on your local machine.)
Steve,
I had exactly the same symptoms when I was debugging web proxy I was developing. It turned out that Fiddler was correcting the CRLF (\r\n) chars that go after the last byte of last header and before first byte of request body. According to HTTP spec, there should be exactly two CRLFs and my proxy was adding three of them there (due to a bug) and Fiddler was silently correcting this.
Not sure if this is the same problem in your case, as you are using proxies, but maybe it will help you somehow.
On the client machine I need to be able to somehow detect which sites the current user are looking at right now.
I know the base URL of the sharepoint app, say sharepoint.thecompany.net but how the hack do I get the last requested url from the server?
I have hit a dead stop when trying to iterate the current processes and the casting the iexplorer process to something I can work with, I just don't know which kind of object to cast the process to :-(
I hope to implement this logic in a C# assembly what should run on the client box.
Any other approach that might work?
Thanks in advance
WatiN will allow you to attach to IE instances and get the current url from them. It will also allow you to do the same with Firefox instances.
It might be more efficient however to try to get requested urls at the network level using a wireshark type concept where you are just listening to http traffic on the computer and keeping track of the urls but a solution like that is a bit over my head.
EDIT: I came across this while looking for a solution: http://www.codeproject.com/KB/IP/networkmonitor.aspx
From what I can see I would think you could adapt the monitoring code to monitor and look for http request packets and parse the headers for the url information you need.