我已经创建了一个wcf服务来测试wcf超时。我的问题是甚至超时已过期其仍然有效。当前线程甚至服务超时?
在此服务中,我创建了长时间运行的方法,并在那里创建了日志文件,然后让服务超时。但即使服务超时也过期了,仍然有日志文件将数据附加到长时间运行的方法完成执行。 ?
这是怎么发生的?有没有办法阻止?
服务超时1个分钟
长时间运行的方法,持续时间:10分钟
该服务在IIS 7.5托管使用WAS
这里是我的服务实现类
public class LongRunner : ILongRunner
{
public void LongRunnerMethod()
{
int counter = int.Parse(ConfigurationManager.AppSettings["val"]);
string text = string.Empty;
for (int i = 0; true; i++)
{
Thread.Sleep(1000);
if (i >= counter)
break;
text = string.Concat(i.ToString(), DateTime.Now.ToString());
File.AppendAllText(@"C:\Looger\log.txt", text);
}
}
}
这是我的服务界面王牌
[ServiceContract]
public interface ILongRunner
{
[OperationContract]
void LongRunnerMethod();
}
最后这里是web配置
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="val" value="600"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ORServiceBehavior" name="PTS.LongRunner">
<endpoint binding="netTcpBinding" bindingConfiguration="DefaultNetTcpBinding" name="ORServiceTCPEndPoint"
contract="PTS.ILongRunner" address="" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8079/___/_________.svc" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="DefaultNetTcpBinding" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" >
<reliableSession enabled="false" ordered="false" inactivityTimeout="00:10:00"/>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
<security mode="Message">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ORServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" maxConcurrentInstances="200" />
<dataContractSerializer maxItemsInObjectGraph="50000" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
我编辑了自己的冠军。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –
[为什么WCF不支持服务端超时?](http://stackoverflow.com/questions/4974640/why-doesnt-wcf-support-service-side-timeouts) –