Пример #1
0
        /// <summary>
        /// Deserialisiert für den WebService-Proxytyp <paramref name="webServiceType"/> den zugehörigen SoapClientType und
        /// registriert diesen im statischen Cache von <see cref="WebClientProtocol"/>.
        /// </summary>
        /// <param name="webServiceType">Der WebService-Proxytyp.</param>
        public static void DeserializeClientType(Type webServiceType)
        {
            using (var log = new EnterExitLogger(s_log, Level.Info, "webServiceType = {0}", webServiceType)) {
                if (!IsCached(webServiceType))
                {
                    var filename = GetSerializerPath(webServiceType);

                    if (File.Exists(filename))
                    {
                        var formatter = new BinaryFormatter();

                        var webClientProtocolReflector = new TypeReflector(typeof(WebClientProtocol));
                        var cache          = webClientProtocolReflector.GetField("cache");
                        var cacheReflector = new TypeReflector(cache.GetType());
                        //debug: var cacheHashtable = (Hashtable)cacheReflector.GetField(cache, "cache");

                        object deserializedClientType = null;
                        using (var stream = new FileStream(filename, FileMode.Open)) {
                            deserializedClientType = TypeSerializer.Deserialize(formatter, stream);
                            webClientProtocolReflector.Invoke("AddToCache(System.Type, System.Object)",
                                                              new object[] { webServiceType, deserializedClientType });

                            log.Log("added to WebClient cache: {0}", deserializedClientType);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Liefert <c>true</c>, falls der angegebene Webservice Typ bereits im Cache von <see cref="WebClientProtocol"/> vorliegt.
        /// </summary>
        /// <param name="webServiceType">Der WebService-Proxytyp.</param>
        /// <returns>
        /// <c>true</c> falls der angegebene Webservice Typ bereits im Cache von <see cref="WebClientProtocol"/> vorliegt;
        /// sonst <c>false</c>.
        /// </returns>
        public static bool IsCached(Type webServiceType)
        {
            var cachedClientType = s_webClientProtocolReflector.Invoke("GetFromCache(System.Type)", new object[] { webServiceType });

            return(cachedClientType != null);
        }