0
我有一個WCF服務,我已經配置使用serviceThrottling,但是這似乎並沒有工作。WCF serviceThrottling不起作用
我有一個MULT線程客戶端調用該服務@
http://localhost:7778/test/sleep?sleep=1000
和服務器似乎忽略最大??? WCF配置中的設置。
我真的想要做的是增加concurent連接的數量,但它似乎並沒有影響設置。
我的服務器託管如下:
WebServiceHost zHost = new WebServiceHost(typeof (Service1));
zHost.Open();
Console.WriteLine("Started");
Console.ReadLine();
zHost.Close();
在app.config設置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.net>
<connectionManagement>
<add address="*" maxconnection="65535"/>
</connectionManagement>
</system.net>
<system.serviceModel>
<standardEndpoints />
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior0">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="NewBehavior0">
<serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1" maxConcurrentInstances="1" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WCF_REST_TEST_1.Service1">
<endpoint address="/test" behaviorConfiguration="NewBehavior0" binding="webHttpBinding" bindingConfiguration="" contract="WCF_REST_TEST_1.IService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7778" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
如果服務1的設置如下:
[ServiceContract]
public interface IService1
{
[WebGet(UriTemplate = "sleep?sleep={value}", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
CompositeType sleep(int value);
}
和
public class Service1 : IService1
{
public CompositeType sleep(int sleep)
{
Stopwatch sw = new Stopwatch();
sw.Start();
if (sleep > 0)
{
try
{
logger.Log(LogLevel.Info, "Sleep Request recieved: {0}ms", sleep);
Thread.Sleep(sleep);
}
catch (Exception ex)
{
logger.Log(LogLevel.Error, "Error. {0} - {1}", ex.Message, ex.InnerException);
}
}
else
{
logger.Log(LogLevel.Info, "No Sleep value supplied");
}
sw.Stop();
CompositeType zTest = new CompositeType();
zTest.BoolValue = true;
zTest.StringValue = "Some String 2" + sleep;
//zTest.RemoteResponse = responseFromServer;
zTest.RemoteTime = sw.ElapsedMilliseconds;
return zTest;
}
}
我不確定我是否低。我在我的帖子中說,即使我的配置設置爲maxConcurrentCalls =「1」maxConcurrentSessions =「1」maxConcurrentInstances =「1」...它不工作。 – 2013-05-03 03:09:50
你的配置看起來和我的配置完全一樣,你剛剛提高了對我的配置沒有任何影響的值。 – 2013-05-03 03:10:25