Exemplo n.º 1
0
        public static T GetProxy <T>(string externalConfigPath)
        {
            var channelFactory = new ExtendedChannelFactory <T>(externalConfigPath);

            channelFactory.Open();
            return(channelFactory.CreateChannel());
        }
Exemplo n.º 2
0
        public static object CallRemoteService(string AssemblyName, string MethodName, object[] Parameters)
        {
            try
            {
                var configFile = AppDomain.CurrentDomain.BaseDirectory + "\\" + Application.ProductName + ".exe.config";
                configFile = Path.GetFullPath(configFile);
                Hashtable Result = null;
                //var proxy = WcfClientHelper.GetProxy<ITransferService>(configFile);
                using (ExtendedChannelFactory <ITransferService> channelFactory =
                           new ExtendedChannelFactory <ITransferService>(configFile))
                {
                    channelFactory.Open();
                    ITransferService proxy = channelFactory.CreateChannel();
                    using (proxy as IDisposable)
                    {
                        Hashtable hashtable = new Hashtable();
                        hashtable["assembly_name"]     = AssemblyName;
                        hashtable["method_name"]       = MethodName;
                        hashtable["method_paremeters"] = Parameters;

                        Stream source_stream = Yqun.Common.Encoder.Serialize.SerializeToStream(hashtable);
                        Stream zip_stream    = Yqun.Common.Encoder.Compression.CompressStream(source_stream); source_stream.Dispose();
                        Stream stream_result = proxy.InvokeMethod(zip_stream); zip_stream.Dispose();
                        Stream ms            = ReadMemoryStream(stream_result); stream_result.Dispose();
                        Stream unzip_stream  = Yqun.Common.Encoder.Compression.DeCompressStream(ms); ms.Dispose();
                        Result = Yqun.Common.Encoder.Serialize.DeSerializeFromStream(unzip_stream) as Hashtable;
                    }
                    channelFactory.Close();
                }
                return(Result["return_value"]);
            }
            catch (Exception ex)
            {
                logger.Error(MethodName + "  " + ex.ToString());
                throw new ServiceAccessException(ex.Message, ex);
            }
        }