积极答复者
重新发一下“WCF服务是不是比WEB服务慢”

问题
答案
-
Hi,
你的问题很好。
呵呵,测试工作也很有意义。对学习很有帮助。
1.WCF与ASP.NET Web Service:
WCF核心也支持Web服务的行业标注,支持SOAP协议。当2者都使用一样的协议的时候在做比较。
2.测试方法:
在相同的条件下测试才有比较的意义。如果单纯作为Web服务来使用,WCF和Web服务没什么区别。你把2个服务都在IIS里托管,然后可以客户端调用WCF服务。WCF使用BasicHttpBinding,这样才算是相同条件,否则WCF使用TcpBinding,Web服务肯定与其无法相比。
其次第一次调用不要计算在内,因为第一次包涵编译文件、加载类库等操作,需要耗费较多的时间,你可以在第一次调用成功以后在做100次调用,然后取总的时间比较,这样才会减小误差。
你在看看时间的差别。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum- 已标记为答案 Mog Liang 2010年1月4日 6:32
全部回复
-
我是这样测试的,不知道对不对
直接在一个解决方案里加了三个项目,一个控制台项目,一个WCF服务项目,一个WEB服务项目namespace WcfService2 { public class Service1 : IService1 { public string GetData(string input) { return input; } } }
namespace WebService1 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { [WebMethod] public string GetData(string input) { return input; } } }
其实就是一模一样,然后我没有发布到IIS上,而是在编译成功后,直接在控制台项目中引用服务里搜索本解决方案中的服务
控制台部分DateTime t = DateTime.Now; ServiceReference1.Service1Client s = new ConsoleApplication1.ServiceReference1.Service1Client(); Console.WriteLine(s.GetData("111")); DateTime t1 = DateTime.Now; TimeSpan ts = t1 - t; Console.WriteLine(ts.TotalMilliseconds+"毫秒"); DateTime t2 = DateTime.Now; ServiceReference2.Service1SoapClient s1 = new ConsoleApplication1.ServiceReference2.Service1SoapClient(); Console.WriteLine(s1.GetData("111")); DateTime t3 = DateTime.Now; TimeSpan ts1 = t3 - t2; Console.WriteLine(ts1.TotalMilliseconds + "毫秒"); //output //111 //1050 //111 //170
这么简单的方法,这么点数据,竟然慢了这么多??
不知道是我测试的方法错了还是因为我没真正的发布出来- 已合并 Mog Liang 2009年12月29日 2:35 same question
-
Hi,
你的问题很好。
呵呵,测试工作也很有意义。对学习很有帮助。
1.WCF与ASP.NET Web Service:
WCF核心也支持Web服务的行业标注,支持SOAP协议。当2者都使用一样的协议的时候在做比较。
2.测试方法:
在相同的条件下测试才有比较的意义。如果单纯作为Web服务来使用,WCF和Web服务没什么区别。你把2个服务都在IIS里托管,然后可以客户端调用WCF服务。WCF使用BasicHttpBinding,这样才算是相同条件,否则WCF使用TcpBinding,Web服务肯定与其无法相比。
其次第一次调用不要计算在内,因为第一次包涵编译文件、加载类库等操作,需要耗费较多的时间,你可以在第一次调用成功以后在做100次调用,然后取总的时间比较,这样才会减小误差。
你在看看时间的差别。
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum- 已标记为答案 Mog Liang 2010年1月4日 6:32
-
已经在这里和你讨论了。
http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/3aa96444-56e4-4924-87cb-b3bc5e2377b7
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum -
恩,对,我回去后又测试了多次的情况,恰好我用的就是100次奇怪的事发生了,WebService正常被调用,WCF连续执行了6 7次不动了,卡住了。之后停止调试,重新启动调试,WCF根本一次都不执行了,很费解,于是重新编译了一下WCF,恩,可以调用了,但是还是和上面的情况一样,执行6 7次就卡住了,然后重新启动调试后一次都调用不了,这样的情况我发布到IIS(5.1)上也会出现。WCF的配置文件是这样配置的:<system.serviceModel><services><service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior"><!-- Service Endpoints --><endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1"><identity><dns value="localhost"/></identity></endpoint><endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/></service></services><behaviors><serviceBehaviors><behavior name="WcfService1.Service1Behavior"><serviceMetadata httpGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="false"/></behavior></serviceBehaviors></behaviors></system.serviceModel>
-
这个应该是WCF默认的限流设置导致的。
修改服务的并发设置:
serviceBehaviors>
<behavior name="WCFService.WCFServiceBehavior">
<serviceTimeouts transactionTimeout="00:01:00"/>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="1000" maxConcurrentSessions="1000"/>-->
</behavior>
</serviceBehaviors>
不然会阻塞进程,无法处理客户端并发请求。
参考一下:
http://www.cnblogs.com/frank_xl/archive/2009/07/22/1528911.html
http://www.cnblogs.com/frank_xl/archive/2009/06/27/1509845.html
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
欢迎访问老徐的中文技术博客:Welcome to My Chinese Technical Blog
欢迎访问微软WCF中文技术论坛:Welcome to Microsoft Chinese WCF Forum
欢迎访问微软WCF英文技术论坛:Welcome to Microsoft English WCF Forum