나는 WCF를 사용하여 WINDOWS 서비스 호스팅 Calc 엔진을 개발하는 첫 발을 내디뎠다. 서비스는 훌륭하게 작동하지만 모든 호출에 대해 하나의 스레드 만 사용하는 것처럼 보이지만 확장 가능하고 멀티 스레딩을 사용해야합니다.자체 호스팅 WCF 서비스 : ConcurrencyMode.Multiple하지만 하나의 스레드 만 사용하고 있습니까?
이 응용 프로그램의 초기 단계이므로 코드의 모든 추적을 무시하십시오.
서비스 시작시 메모리로 정보를 읽는 (ThirdParty.Initialise (strInit)) 일부 타사 소프트웨어 (COM)를 호출 한 다음 ProcessInformation을 호출 할 때마다 주어진 XML 문자열에서 계산 된 결과가 반환됩니다.
지금까지 모든 호출은 ServiceBehavior를 설정 한 것과 상관없이 하나의 스레드를 사용하는 것처럼 보였습니다. 얼마나 많은 개별 소비자가 사용하던간에 - 아무도 도움이 될 수 있습니까?
코드 개요 :
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall, UseSynchronizationContext = false)]
public class TestWCFService : ITestWCFService
{
private static ThirdPartyLib.ThirdPartyComClass ThirdParty;
private static bool initCalled = false;
private static int cntInit = 0;
private static int cntTrans = 0;
public TestWCFService()
{
if (ThirdParty == null)
{
ThirdParty = new ThirdPartyLib.ThirdPartyComClass();
}
}
public bool InitialiseThirdParty(string strInit, out string strError)
{
try
{
if (!initCalled)
{
cntInit++;
ThirdParty.Initialise(strInit);
initCalled = true;
}
strError = "Call Num " + cntInit;
return true;
}
catch (Exception ex)
{
strError = "ThirdParty.Initialise exception " + ex.Message + " 0n call number " + cntInit;
return false;
}
}
public bool ProcessInformation(string strRequestXML, int quoteMarker, out string strResponseXML, out string strError, out int quoteMarkerReturned)
{
try
{
cntTrans++;
quoteMarkerReturned = quoteMarker;
ThirdParty.ProcessInformation(strRequestXML, out strResponseXML);
strError = "Call Trans Num " + cntTrans;
return true;
}
catch (Exception ex)
{
strError = ex.Message + " On call trans num " + cntTrans;
strResponseXML = "Error";
quoteMarkerReturned = quoteMarker;
return false;
}
}
}
구성 : 마이크로 소프트 워드 프로세서 당
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TestServiceBinding" bypassProxyOnLocal="true"
useDefaultWebProxy="false">
<readerQuotas maxDepth="524288" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<reliableSession inactivityTimeout="00:30:00" enabled="true" />
</binding>
</wsHttpBinding>
<mexHttpBinding>
<binding name="MEXTestServiceBinding" openTimeout="00:02:00"
sendTimeout="00:02:00" />
</mexHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="TestWcfServiceLibrary.TestWCFServiceBehavior"
name="TestWcfServiceLibrary.TestWCFService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="TestServiceBinding"
name="" contract="TestWcfServiceLibrary.ITestWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="MEXTestServiceBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/TestWcfServiceLibrary/TestWCFService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TestWcfServiceLibrary.TestWCFServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="100" maxConcurrentInstances="100"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
하나의 스레드 만 사용된다는 것을 어떻게 알 수 있습니까? 귀하의 제 3 자 COM 구성 요소가 아파트 스레드이며 그래서 스레드 친 화성을 가지고있는 것 같아요. 그러나 많은 .NET 스레드가 서비스 구현에 사용되고 있습니다. 그들은 유일한 STA 스레드를 사용하기 위해 모두 대기열에 있어야합니다. COM 개체를 호출 할 수 있습니다. –