AppFabric Cache - An existing connection was forci

2019-03-16 03:22发布

问题:

I'm trying to get AppFabric cache up and running on my local development environment. I have Windows Server AppFabric Beta 2 Refresh installed, and the cache cluster and host configured and started running on Windows 7 64-bit. I'm running my MVC2 website in a local IIS website under a v4.0 app pool in integrated mode.

HostName : CachePort      Service Name            Service Status Version Info
--------------------      ------------            -------------- ------------
SN-3TQHQL1:22233          AppFabricCachingService UP             1 [1,1][1,1]

I have my web.config configured with the following:

  <configSections>
        <section name="dataCacheClient" type="Microsoft.ApplicationServer.Caching.DataCacheClientSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowLocation="true" allowDefinition="Everywhere"/>
   </configSections>

   <dataCacheClient>
       <hosts>
           <host name="SN-3TQHQL1" cachePort="22233" />
       </hosts>
   </dataCacheClient>

I'm getting an error when I attempt to initialize the DataCacheFactory:

    protected CacheService()
    {
        _cacheFactory = new DataCacheFactory(); <-- Error here
        _defaultCache = _cacheFactory.GetDefaultCache();
    }

I'm getting the ASP.NET yellow error screen with the following:

An existing connection was forcibly closed by the remote host

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Source Error:

Line 21:         protected CacheService()
Line 22:         {
Line 23:             _cacheFactory = new DataCacheFactory();
Line 24:             _defaultCache = _cacheFactory.GetDefaultCache();
Line 25:         }

回答1:

I had a similar issue as well, and my problem was I had not given the proper permissions to the cache client. In order to quickly verify this is the issue I would grant the everyone account access to the cache. If this fixes the issue then look into limiting access to the appropriate account rather than everyone. This can done executing the following command via the "Caching Administrator Windows PowerShell", which is found in the Windows Server AppFabric start menu folder:

Grant-CacheAllowedClientAccount everyone


回答2:

I had this problem too and I found the answer in this thread:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/c27063e7-1579-4d62-9104-87076d1c8d98/client-caching-error-errorcodeerrca0017substatuses0006

The answer:

You are seeing this error because of the security property mismatch between client and server.

In your client code you disabled the security (Mode=None and PotectionLevel=None) whereas the cache server uses mode=Transport and PotectionLevel=EncryptAndSign (default in Beta2Fresh bits).

Do either of the following:

1) In the client code use the default security i.e. configuration.SecurityProperties =new DataCacheSecurity();

2) Disable the security at server to match with your existing client code. Use Powershell cmdlet Set-CacheClusterSecurity -SecurityMode None -ProtectionLevel None



回答3:

Do you get the same problem if you use a DataCacheFactoryConfiguration object? e.g.

protected CacheService()
{
    DataCacheFactoryConfiguration config;
    List<DataCacheServerEndpoint> endpoints;
    DataCacheFactory factory;
    DataCache cache;

    endpoints = new List<DataCacheServerEndpoint>();
    endpoints.Add(new DataCacheServerEndpoint("SN-3TQHQL1",22233));

    config = new DataCacheFactoryConfiguration();
    config.Servers = endpoints;

    factory = new DataCacheFactory(config);

    cache = factory.GetDefaultCache();
    ...
}

Have you opened the port on your firewall?

Maybe check entries in your event logs - they may offer clues as to what is (or isn't) happening.