1
我有一個將數據發送給訂閱客戶端的WCF服務。使用順序循環的過程非常緩慢,因爲循環內有3個循環,例如;並行回撥給用戶
for (int x = 0 ; x <= MasterTables.count - 1 ;x ++)
{
for (int y = 0; y <= MasterData[x].count ; y++)
{
foreach (SubList subscriber in subscribers.ToList())
{
SendDatatoSubscriber();
}
}
}
所以不是我把連續循環到並行循環,而這又是快得多,但向下側是服務器同時發佈許多回調給單個用戶,因此,傳輸信道超時。
SendDatatoSubscriber()事件是一個同步調用,因爲我需要客戶端確認它已收到對象並將特定消息返回給服務器,因爲有更多事件依賴於此結果。
我的web配置,客戶端配置情況如下:
服務配置:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="None"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpSecure" closeTimeout="23:00:00" openTimeout="23:00:00" receiveTimeout="23:00:00" sendTimeout="23:00:00" transactionFlow="false" transferMode="Buffered" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2000" maxReceivedMessageSize="2147483647" portSharingEnabled="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<reliableSession inactivityTimeout="23:00:00" enabled="false"/>
<security mode="Message">
<transport clientCredentialType="None">
<extendedProtectionPolicy policyEnforcement="Never"/>
</transport>
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="service.ClientBehavior" name=" service.DTSClient">
<endpoint address="" behaviorConfiguration="WcfDts.DTSClientEndpointBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpSecure" name="ClientNetTcp" contract="WcfDts.IDTSClient"/>
<endpoint address="mex" binding="mexHttpBinding" behaviorConfiguration="WcfDts.DTSClientEndpointBehavior" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:8000/WcfDts/Services"/>
</baseAddresses>
<timeouts closeTimeout="23:00:00"/>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name=" service.DTSClientEndpointBehavior">
<wsdlExtensions location="http://127.0.0.1/ service /Services/DTSClient.svc" singleFile="True"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name=" service.ClientBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType=" service.CustomUserNameValidator, service "/>
<serviceCertificate findValue="CertName" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<clientCertificate>
<certificate findValue=" CertName " storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
</clientCertificate>
</serviceCredentials>
<serviceThrottling maxConcurrentCalls="2000" maxConcurrentInstances="2000" maxConcurrentSessions="2000"/>
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
客戶端配置:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="ClientNetTcp" closeTimeout="23:59:59" openTimeout="23:59:59" receiveTimeout="23:59:59" sendTimeout="23:59:59" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="100000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="100000" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true" inactivityTimeout="23:59:59" enabled="false"/>
<security mode="Message">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign"/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://BaseAdress:Port/Services/Service.svc" binding="netTcpBinding" bindingConfiguration="ClientNetTcp" contract="Sub.IClient" name="ClientNetTcp">
<identity>
<dns value="CertName"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
所以我的問題是:
- 我是否需要修改配置遏制超時情況
- 或者我如何讓訂閱者收到並行的回調?
這就是我做的..雖然我仍然得到超時..現在在服務器端..很奇怪......必須是一個合乎邏輯的流程...可能超時是由端口共享造成的嗎?當我使用端口發送數據到客戶端和客戶端使用相同的渠道上傳其他數據到服務器...我想創建兩個單獨的服務..但如果端口共享不是一個問題,然後我不想觸摸我現有的邏輯...請指教 – Kush 2013-02-11 15:55:07