views:

456

answers:

2

Hi,

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.

A: 

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.

Robert
+1  A: 

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).

Christopher