【发布时间】:2011-11-14 11:06:09
【问题描述】:
我们使用 WCF (BasicHttpBinding) 从 C# 应用程序调用 Web 服务,这需要大约 300 毫秒。我们注意到,从 SOAP UI 发送相同的 SOAP 调用只需要大约 30 毫秒。
现在我们还实现了一个通过基本 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);
});
}
我在这里遗漏了什么吗?任何想法都会有所帮助... ;-)
亲切的问候, 塞巴斯蒂安
【问题讨论】:
-
在 WCF 下对同一程序中同一服务的后续调用需要多长时间?检查一次做一件事的时间长度并不是对性能的可靠测试 - 做很多次。
-
第一个 WCF 调用甚至更慢,但 WCF 中的后续调用和普通 WebClient 调用仍然比相应的 Java 客户端(甚至 SoapUI)慢 10 倍左右。我确实在循环中运行了测试,以确保测量平均情况......
标签: java .net performance web-services soap