我在IIS中托管了一个简单的WCF RESTful服务。我使用浏览器调用WCF。我使用浏览器中的不同选项卡同时调用该服务。以下是服务的代码
[ServiceContract]
public interface IWCFService
{
[OperationContract]
[WebGet(UriTemplate = "DoWork", ResponseFormat = WebMessageFormat.Json)]
string DoWork();
}
public class WCFService : IWCFService
{
public string DoWork()
{
string ret = "Enter time is " + System.DateTime.Now + " " + System.DateTime.Now.Millisecond;
System.Threading.Thread.Sleep(10000);
ret += ". Exiting time is " + System.DateTime.Now + " " + System.DateTime.Now.Millisecond;
return ret;
}
}
以下是web.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WCFService.WCFServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WCFService.WCFServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WCFService.WCFServiceBehavior" name="WCFService.WCFService">
<endpoint address="" binding="webHttpBinding" contract="WCFService.IWCFService" behaviorConfiguration="WCFService.WCFServiceBehavior">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
即使我快速连续输入地址,第一个的结束时间是第二个的开始时间,例如一页的输出是
然后下一页是
可能导致此问题的原因以及如何解决此问题,以便所有来电一到达就会立即处理?
答案 0 :(得分:1)
我不确定但您可以尝试使用实现类上的ServiceBehavior属性设置ConcurrencyMode
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class WCFService : IWCFService