string CreateKey(Type protocolType, Type serverType, bool excludeSchemeHostPort = false, string keySuffix = null) { // // we want to use the hostname to cache since for documentation, WSDL // contains the cache hostname, but we definitely don't want to cache the query string! // string protocolTypeName = protocolType.FullName; string serverTypeName = serverType.FullName; string typeHandleString = serverType.TypeHandle.Value.ToString(); string url = excludeSchemeHostPort ? Request.Url.AbsolutePath : Request.Url.GetLeftPart(UriPartial.Path); int length = protocolTypeName.Length + url.Length + serverTypeName.Length + typeHandleString.Length; StringBuilder sb = new StringBuilder(length); sb.Append(protocolTypeName); sb.Append(url); sb.Append(serverTypeName); sb.Append(typeHandleString); if (keySuffix != null) { sb.Append(keySuffix); } CreateCustomKeyForAspNetWebServiceMetadataCache createKey = ServerProtocol.GetCreateCustomKeyForAspNetWebServiceMetadataCacheDelegate(serverType); return(createKey(protocolType, serverType, sb.ToString())); }
static CreateCustomKeyForAspNetWebServiceMetadataCache GetCreateCustomKeyForAspNetWebServiceMetadataCacheDelegate(Type serverType) { PartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); string key = "CreateCustomKeyForAspNetWebServiceMetadataCache-" + serverType.FullName; CreateCustomKeyForAspNetWebServiceMetadataCache result = (CreateCustomKeyForAspNetWebServiceMetadataCache)HttpRuntime.Cache.Get(key); if (result == null) { MethodInfo createKeyMethod = serverType.GetMethod( "CreateCustomKeyForAspNetWebServiceMetadataCache", BindingFlags.Public | BindingFlags.Static | BindingFlags.ExactBinding | BindingFlags.FlattenHierarchy, null, new Type[] { typeof(Type), typeof(Type), typeof(string) }, null); if (createKeyMethod == null) { result = ServerProtocol.DefaultCreateCustomKeyForAspNetWebServiceMetadataCache; } else { result = delegate(Type pt, Type st, string originalString) { return((string)createKeyMethod.Invoke(null, new object[] { pt, st, originalString })); }; } HttpRuntime.Cache.Add(key, result, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null); } return(result); }