How do I configure a C# web service client to send HTTP request header and body in parallel?
Asked Answered
S

2

8

I am using a traditional C# web service client generated in VS2008 .Net 3.5, inheriting from SoapHttpClientProtocol. This is connecting to a remote web service written in Java.

All configuration is done in code during client initialization, and can be seen below:

        ServicePointManager.Expect100Continue = false;
        ServicePointManager.DefaultConnectionLimit = 10;

        var client = new APIService
        {
            EnableDecompression = true,
            Url = _url + "?guid=" + Guid.NewGuid(),
            Credentials = new NetworkCredential(user, password, null),
            PreAuthenticate = true,
            Timeout = 5000 // 5 sec
        };

It all works fine, but the time taken to execute the simplest method call is almost double the network ping time. Whereas a Java test client takes roughly the same as the network ping time:

C# client ~ 550ms
Java client ~ 340ms
Network ping ~ 300ms

After analyzing the TCP traffic for a session discovered the following:

Basically, the C# client sent TCP packets in the following sequence.

Client Send HTTP Headers in one packet.
Client Waits For TCP ACK from server.
Client Sends HTTP Body in one packet.
Client Waits For TCP ACK from server.

The Java client sent TCP packets in the following sequence.

Client Sends HTTP Headers in one packet.
Client Sends HTTP Body in one packet.
Client Revieves ACK for first packet.
Client Revieves ACK for second packet.
Client Revieves ACK for second packet.

Is there anyway to configure the C# web service client to send the header/body in parallel as the Java client appears to?

Any help or pointers much appreciated.

Sinfonietta answered 10/3, 2010 at 15:1 Comment(4)
Can you sniff the http headers for the .Net request and the java request and compare them? (And I guess the java client uses the same proxy)Holloman
sorry, when i say proxy i mean as in a a proxy class, rather than an http proxySinfonietta
edited text to remove references to 'proxy' and replace with 'client'Sinfonietta
Add a http debugging proxy like fiddler and then sniff the packet content. you should get some info.Hearthstone
D
1

Thanks for the reply Rob, eventually I opted to use the Add Service Reference / WCF proxy generation, which does this by default. Probably because it's using newer HTTP libraries underneath.

I did have a few WCF proxy generation issues with SOAP methods that return raw arrays of complex objects (i.e.: returning an object that contains an array of objects worked fine). To get round this you either have to wrap your arrays in objects, or switch the SOAP server config from RPC to DOCUMENT (which is what we did).

Dustheap answered 29/4, 2010 at 9:4 Comment(0)
I
0

I think you can use the inherited EndGetRequestStream method to hack the SoapHttpClientProtocol. Save that to a buffer until the request has finished. Then make your own stream and push it all out at once.

Innards answered 28/4, 2010 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.