WCF客户端性能

时间:2012-05-11 20:47:02

标签: wcf

我使用WCF来调用基于Java的Web服务,并且不断获得1.4秒或1.5秒的响应时间。我在SoapUI中使用完全相同的SOAP请求来调用相同的Web服务,并且不断获得0.9秒到1秒的响应时间。

这两个请求都是从我的本地计算机发起的,两个请求都是同一个目标。

我很难相信序列化和反序列化需要0.5秒,但除此之外还有什么可以影响性能?

更新1 - 包含示例代码

        Stopwatch sw = new Stopwatch();

        //Trust all certificates, non-production uses self-signed certificate
        System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

        MyServiceClient.MyService.Spml2ServicePortTypeClient client = new MyServiceClient.MyService.Spml2ServicePortTypeClient();

        client.ClientCredentials.UserName.UserName = "username";
        client.ClientCredentials.UserName.Password = "password";

        for (int i = 0; i < 5; i++)
        {
            MyServiceClient.MyService.SuggestUserIDRequestType webRequest = new MyServiceClient.MyService.SuggestUserIDRequestType();
            webRequest.requestID = "MyId";
            webRequest.givenName = "Hardy";
            webRequest.sn = "Wang";
            webRequest.uid = "some value";

            sw.Start();
            MyServiceClient.MyService.SuggestUserIDResponseType response = client.suggestUserID(webRequest);
            sw.Stop();

            Console.WriteLine("Elapsed time {0} ms.", sw.ElapsedMilliseconds);
            sw.Reset();

        }

0 个答案:

没有答案