Java and Net HTTP Client Performance

We call the web service from our C # application, which takes about 300 ms using WCF (BasicHttpBinding). We noticed that the same SOAP call takes about 30 ms when sending it from the SOAP user interface.

Now we have also implemented access control for the web service through the base WebClient to ensure that the DeSer part for WCf is not causing this additional delay. When using the WebClient class, the call takes about 300 ms.

Any ideas on why Java is about 10 times faster than C # in this regard? Is some kind of setup possible on the .NET side?

private void Button_Click(object sender, RoutedEventArgs e) { executeTest(() => { var resultObj = client.getNextSeqNr(new WcfClient() { domain = "?", hostname = "?", ipaddress = "?", loginVersion = "?", processId = "?", program = "?", userId = "?", userIdPw = "?", userName = "?" }, "?", "?"); }); } private void Button_Click_1(object sender, RoutedEventArgs e) { WebClient webClient = new WebClient(); executeTest(()=> { webClient.Proxy = null; webClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); webClient.Headers.Add("Content-Type", "application/xml"); webClient.Encoding = Encoding.UTF8; var data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"SomeNamespace\">" + " <soapenv:Header/>" + " <soapenv:Body>" + " <ser:getNextSeqNr>" + " <!--Optional:-->" + " <clientInfo>" + " <!--Optional:-->" + " <domain>?</domain>" + " <!--Optional:-->" + " <hostname>?</hostname>" + " <!--Optional:-->" + " <ipaddress>?</ipaddress>" + " <!--Optional:-->" + " <loginVersion>?</loginVersion>" + " <!--Optional:-->" + " <processId>?</processId>" + " <!--Optional:-->" + " <program>?</program>" + " <!--Optional:-->" + " <userId>*</userId>" + " <!--Optional:-->" + " <userIdPw>?</userIdPw>" + " <!--Optional:-->" + " <userName>?</userName>" + " </clientInfo>" + " <!--Optional:-->" + " <name>?</name>" + " <!--Optional:-->" + " <schema>?</schema>" + " </ser:getNextSeqNr>" + " </soapenv:Body>" + "</soapenv:Envelope>"; string result = webClient.UploadString("http://server:8080/service", "POST", data); }); } 

Am I missing something? Any idea would be helpful ...; -)

Regards, Sebastian

+4
source share
1 answer

I just found the reason for this.

This is a 100-Expect Continue HTTP Header and the corresponding implementation in .NET. The .NET client expects a default of 350 ms on the server. This leads to delays. Java seems to have other default values ​​here ...

Just add the following line of code very early in your code:

 System.Net.ServicePointManager.Expect100Continue = false; 

Hooray!

+8
source

Source: https://habr.com/ru/post/1381104/


All Articles