簡體   English   中英

Java與Net HTTP客戶端性能

[英]Java vs. Net HTTP Client Performance

我們從C#app調用web服務,使用WCF(BasicHttpBinding)大約需要300ms。 我們注意到,從SOAP UI發送它時,相同的SOAP調用只需要大約30ms。

現在我們還實現了一個通過基本WebClient訪問Web服務的測試,以確保WCF的DeSer部分不是這個額外延遲的原因。 使用WebClient類時,調用大約需要300毫秒。

關於Java與C#相比為什么在這方面的速度提高了約10倍? 在.NET方面是否可以進行某種調整?

    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);
            });
    }

我在這里錯過了什么嗎? 任何想法都會有所幫助...... ;-)

親切的問候,塞巴斯蒂安

我剛剛找到了原因。

它是100-Expect Continue HTTP Header以及.NET中的相應實現。 .NET客戶端在服務器上默認等待350毫秒。 這導致延遲。 Java似乎在這里有其他默認值...

只需在代碼中盡早添加以下代碼行:

System.Net.ServicePointManager.Expect100Continue = false;

干杯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM