views:

367

answers:

3

I have some C# stubs to a Java web service (Https) (created in Visual Studio 2008, .NET 2.0). The server does not allow requests to be chunked. I was able to set sendChunked to false in the HttpWebRequest.

When I call web service methods which have very little data going across the wire they work fine.
However, when I send requests which contain a significant amount of data, I get an "unable to parse request" error.

Here's the two strange things:

  1. This works fine through Java by setting the HttpConstants.CHUNKED to false, and if you don't do that it breaks with the same "Unable to parse request error".
  2. If I have fiddler running in the background everything works fine?! I believe this is due to Fiddler buffering the request bytes before sending them off. NOTE: if I turn off the Fiddler option to "Decrypt HTTPS" it stops working.
A: 

Ah, the classic "changing the behavior by observing it". The problem is that, as you point out, Fiddler does a bunch of buffering and the like itself. One option may be turning HTTPS off (temporarily), and using a passive network sniffing tool like Wireshark to see if .NET is obeying the settings you're setting.

Jonathan
Is there a way to mimic what Fiddler is doing in my own code?
Alright, I have the request in Wireshark, which I've never used before, do you have a hint what I should be looking for? Can I tell in some way if it is chunked or not?
The info in Wireshark is similar to what you see in Fiddler, just not decoded quite as much. Right-click on one of the packets of your request, and pick 'follow stream'. You'll get a popup window with the data going back and forth -- hopefully you'll see the HTTP headers in there and get a better idea what's going on. Note: Wireshark can *not* see through HTTPS, so you'll have to use standard HTTP to use it. If it doesn't break over HTTP, then this won't help you much.
Jonathan
Thanks Jonathan, I had to switch to HTTP in order to see the stream in Wireshark - which breaks the request. So I can only see that initial packet.
A: 

I'm not clear from your description what you mean by "stubs". Do you mean that you've created a Web Reference to the Java service?

If so, you can override the GetWebRequest method to return your own HttpWebRequest with the SendChunked property set to false:

public partial class Service1
{
    protected override WebRequest GetWebRequest(Uri uri)
    {
        HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
        request.SendChunked = false;
        return request;
    }
}

If this is not what you're asking, then please clarify.

John Saunders
Yes, stubs are the web reference to the Java service.Your code above matches exactly what I have currently. However, it seems like the full request is not getting across to the server for some reason - but does when Fiddler is running.
John Saunders
In particular, this doesn't sound like a chunking problem. That may be a red herring.
John Saunders
BTW, I love the Internet: http://en.wikipedia.org/wiki/Red_herring_(idiom)
John Saunders
A: 

I resolved this issue. Looks like when I create the stubs to the web service methods using "add a web reference" in visual studio it is adding something to the web request which was making the server unhappy. I wrote my own method which creates the XML from scratch and sends the web request without using any of the stubs and it works fine. I hate problems like this.

If you take your modified code, capture the request through Fiddler, and take your original request captured through Fiddler, you can Windiff the two to see exactly how they differ.
EricLaw -MSFT-