我将为一款WPF应用程序设计一个WCF服务。
该服务将被50个客户端使用,并托管于多核服务器上。因此,我希望它是多线程的。
以下是我声明它的方式:
[ServiceContract(
SessionMode = SessionMode.Required,
Namespace = Constants.NameSpace,
CallbackContract = typeof (ISaphirServiceCallback))]
public interface ISaphirService
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,
InstanceContextMode=InstanceContextMode.PerSession)]
public partial class SaphirService : ISaphirService
服务器端配置:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" receiveTimeout="00:59:00" sendTimeout="00:59:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:30:00" enabled="true"/>
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</netTcpBinding>
<customBinding>
<binding name="ServicePECB2ServiceBinding">
<textMessageEncoding messageVersion="Soap12WSAddressing10" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://qualiflps.services-ps.ameli.fr/lps" binding="customBinding" bindingConfiguration="ServicePECB2ServiceBinding" contract="ServiceReference1.ServicePECB2Service" name="ServicePECB2Service" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior0">
<serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="50" maxConcurrentInstances="50"/>
<serviceAuthorization serviceAuthorizationManagerType="Service.Authorizations.AuthorizationPolicy, Service">
<authorizationPolicies>
<add policyType="Service.Authorizations.AuthorizationPolicy, Service" />
</authorizationPolicies>
</serviceAuthorization>
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://127.0.0.1:80/Service" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName" findValue="*****" />
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Service.Authorizations.CustomValidator, Service" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior0" name="Service.Services.SaphirService">
<endpoint address="basic" binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="ServiceInterfaces.IServices.ISaphirService">
<identity>
<dns value="*****" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
以下是客户端配置:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ISaphirService" receiveTimeout="00:30:00" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:30:00" enabled="true"/>
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://****:4224/service/basic" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ISaphirService" contract="ISaphirService" name="NetTcpBinding_ISaphirService" behaviorConfiguration="CustomBehavior">
<identity>
<certificate encodedValue="****" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="CustomBehavior">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerOrChainTrust" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
问题在于,每个请求都在同一个线程上处理。
我在网上查了很多资料,但一切看起来似乎都很好...
你们有什么想法吗?
谢谢!