Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java vs. Net HTTP Client Performance

We call a webservice from our C# app which takes about 300ms using WCF (BasicHttpBinding). We noticed that the same SOAP call does only take about 30ms when sending it from SOAP UI.

Now we also implemented a test accessing the webservice via a basic WebClient in order to make sure that the DeSer-part of the WCf is not the reason for this additional delay. When using the WebClient class the call takes about 300ms as well.

Any ideas on why Java compared to C# is about 10x faster in this regard? Is there some kind of tweaking possible on the .NET side of things?

    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 here? Any idea would be helpful... ;-)

Kind regards, Sebastian

like image 210
Sebastian Becker Avatar asked Feb 22 '23 10:02

Sebastian Becker


1 Answers

I just found the reason for this.

It's the 100-Expect Continue HTTP Header and the corresponding implementation in .NET. The .NET client wait 350ms as default on the server. This causes the 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;

Cheers!

like image 65
Sebastian Becker Avatar answered Feb 26 '23 22:02

Sebastian Becker