예제 #1
0
        static IOpenApi GetChannel()
        {
            var             client = new System.ServiceModel.ChannelFactory <IOpenApi>(new BasicHttpBinding());
            EndpointAddress ad     = new EndpointAddress("http://localhost:18346/OpenApi.svc");

            return(client.CreateChannel(ad));
        }
예제 #2
0
파일: MainForm.cs 프로젝트: ck0074451665/MB
 private void button4_Click(object sender, EventArgs e)
 {
     System.ServiceModel.ChannelFactory<IPatient3> chanel =
        new System.ServiceModel.ChannelFactory<IPatient3>("wsHttpBiding33");
     IPatient3 iPat = chanel.CreateChannel();
     List<PatientInfo> query = iPat.GetPatientInfo();
     dataGridView1.DataSource = query;
     MessageBox.Show("wsHttpBinding33成功");
 }
예제 #3
0
파일: MainForm.cs 프로젝트: ck0074451665/MB
 private void wsHttp_Click(object sender, EventArgs e)
 {
     System.ServiceModel.ChannelFactory<IPatient> chanel =
        new System.ServiceModel.ChannelFactory<IPatient>("wsHttpEndpoint");
     IPatient iPat = chanel.CreateChannel();
     List<PatientInfo> query = iPat.GetPatientInfo();
     dataGridView1.DataSource = query;
     MessageBox.Show("wsHttp成功");
 }
예제 #4
0
        static void Main(string[] args)
        {
            using (var factory = new System.ServiceModel.ChannelFactory <IHomeHandler>("wch"))
            {
                var client = factory.CreateChannel();

                var rt = client.DoWork();
            }
        }
예제 #5
0
 private void Factory_Faulted(object sender, EventArgs e)
 {
     this.OnFactoryFaulted(new ChannelFaultedEventArgs("The Factory has entered a faulted state.", (Exception)null));
     if (this._channelFactory == null)
     {
         return;
     }
     this.RemoveChannelFactoryEvents();
     this._channelFactory.Close(true);
     this._channelFactory = (System.ServiceModel.ChannelFactory <TService>)null;
 }
예제 #6
0
 internal void DisposeFactory(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     if (this._channelFactory != null)
     {
         this.RemoveChannelFactoryEvents();
         this._channelFactory.Close(true);
     }
     this._channelFactory = (System.ServiceModel.ChannelFactory <TService>)null;
 }
        public EmployeeClientProxyFactory(IClientProxySettings proxySettings)
        {
            _proxySettings  = proxySettings;
            _channelFactory = new Lazy <System.ServiceModel.ChannelFactory <IEmployeeService> >(() =>
            {
                var binding         = _proxySettings.GetNetTcpBinding();
                var endpointAddress = _proxySettings.GetEndpointAddress();

                var factory = new System.ServiceModel.ChannelFactory <IEmployeeService>(binding, endpointAddress);
                factory.Endpoint.TrySetMaxItemsInObjectGraph(_proxySettings);

                return(factory);
            });
        }
예제 #8
0
 /// <summary>Closes the service channel and channel factory if they are open, and then invokes <see cref="M:Microsoft.Xrm.Sdk.Client.ServiceProxy`1.AuthenticateCore"></see>.</summary>
 public void Authenticate()
 {
     if (this._serviceChannel != null)
     {
         this._serviceChannel.Close();
         this._serviceChannel.Dispose();
         this._serviceChannel = (Microsoft.Xrm.Sdk.Client.ServiceChannel <TService>)null;
     }
     if (this._channelFactory != null)
     {
         this.RemoveChannelFactoryEvents();
         this._channelFactory.Close(true);
         this._channelFactory = (System.ServiceModel.ChannelFactory <TService>)null;
     }
     this.AuthenticateCore();
 }
예제 #9
0
        public void TestTimeoutSet()
        {
            var uri     = "net.pipe://127.0.0.1/testpipename" + MethodBase.GetCurrentMethod().Name;
            var binding = new System.ServiceModel.NetNamedPipeBinding()
            {
                MaxConnections = 5
            };
            var timeout = 700;

            binding.ReceiveTimeout = TimeSpan.FromMilliseconds(timeout);
            var hang = TimeSpan.FromMilliseconds(timeout * 2);

            using (var server = new System.ServiceModel.ServiceHost(new Service(), new Uri(uri)))
            {
                server.AddServiceEndpoint(typeof(IService), binding, uri);
                server.Open();
                var channelFactory = new System.ServiceModel.ChannelFactory <IService>(binding);

                var client = channelFactory.CreateChannel(new EndpointAddress(uri));
                var result = client.Execute(TimeSpan.FromMilliseconds(0));
                Assert.AreEqual(TimeSpan.FromMilliseconds(0), result);
                CommunicationException timeoutHappenedException = null;
                try
                {
                    result = client.Execute(hang);
                }
                catch (CommunicationException ex)
                {
                    timeoutHappenedException = ex;
                }
                Assert.NotNull(timeoutHappenedException);
                Assert.AreEqual(typeof(System.IO.IOException), timeoutHappenedException.InnerException.GetType());
                var channel = client as IContextChannel;
                Assert.AreEqual(CommunicationState.Faulted, channel.State);
                try
                {
                    result = client.Execute(TimeSpan.FromMilliseconds(0));
                }
                catch (CommunicationObjectFaultedException afterTimeoutExeption)
                {
                }
                client = channelFactory.CreateChannel(new EndpointAddress(uri));
                result = client.Execute(TimeSpan.FromMilliseconds(0));
            }
        }
예제 #10
0
파일: Program.cs 프로젝트: jixer/sb-demos
        static void Main(string[] args)
        {
            using (var factory = new System.ServiceModel.ChannelFactory<IInventoryService>("IInventoryService"))
            {
                factory.Faulted += Handle_Fault;
                var client = factory.CreateChannel();

                Console.WriteLine("Connected to the queue.  Type in a product name to submit an order or type 'q' + <ENTER> to quit...");
                string productName = Console.ReadLine();
                while (productName != "q")
                {
                    var req = new OrderRequest { Product = productName };
                    client.SubmitOrder(req);
                    Console.WriteLine("Order for product '{0}' submitted...", productName);
                    productName = Console.ReadLine();
                }
            }
        }
예제 #11
0
        public void TestTcpUrl()
        {
            using (var server = new System.ServiceModel.ServiceHost(new Service(), new Uri("net.tcp://127.0.0.1:6782")))
            {
                var binding = new System.ServiceModel.NetTcpBinding() {MaxConnections = 5};
                server.AddServiceEndpoint(typeof(IService), binding, "net.tcp://127.0.0.1:6782");
                server.Open();
                Thread.Sleep(100);
                using (var channelFactory = new System.ServiceModel.ChannelFactory<IService>(binding))
                {

                    var client = channelFactory.CreateChannel(new EndpointAddress("net.tcp://127.0.0.1:6782"));
                    var result = client.Execute(new byte[]{1});
                    Assert.AreEqual(1,result[0]);

                }
            }
        }
예제 #12
0
 public void TestTcpUrl()
 {
     using (var server = new System.ServiceModel.ServiceHost(new Service(), new Uri("net.tcp://127.0.0.1:6782")))
     {
         var binding = new System.ServiceModel.NetTcpBinding()
         {
             MaxConnections = 5
         };
         server.AddServiceEndpoint(typeof(IService), binding, "net.tcp://127.0.0.1:6782");
         server.Open();
         Thread.Sleep(100);
         using (var channelFactory = new System.ServiceModel.ChannelFactory <IService>(binding))
         {
             var client = channelFactory.CreateChannel(new EndpointAddress("net.tcp://127.0.0.1:6782"));
             var result = client.Execute(new byte[] { 1 });
             Assert.AreEqual(1, result[0]);
         }
     }
 }
예제 #13
0
        public void TestTimeoutSet()
        {
            var uri = "net.pipe://127.0.0.1/testpipename" + MethodBase.GetCurrentMethod().Name;
            var binding = new System.ServiceModel.NetNamedPipeBinding() { MaxConnections = 5 };
            var timeout = 700;
            binding.ReceiveTimeout = TimeSpan.FromMilliseconds(timeout);
            var hang = TimeSpan.FromMilliseconds(timeout * 2);
            using (var server = new System.ServiceModel.ServiceHost(new Service(), new Uri(uri)))
            {
                server.AddServiceEndpoint(typeof(IService), binding, uri);
                server.Open();
                var channelFactory = new System.ServiceModel.ChannelFactory<IService>(binding);

                var client = channelFactory.CreateChannel(new EndpointAddress(uri));
                var result = client.Execute(TimeSpan.FromMilliseconds(0));
                Assert.AreEqual(TimeSpan.FromMilliseconds(0), result);
                CommunicationException timeoutHappenedException = null;
                try
                {
                    result = client.Execute(hang);
                }
                catch (CommunicationException ex)
                {
                    timeoutHappenedException = ex;

                }
                Assert.NotNull(timeoutHappenedException);
                Assert.AreEqual(typeof(System.IO.IOException), timeoutHappenedException.InnerException.GetType());
                var channel = client as IContextChannel;
                Assert.AreEqual(CommunicationState.Faulted, channel.State);
                try
                {
                    result = client.Execute(TimeSpan.FromMilliseconds(0));
                }
                catch (CommunicationObjectFaultedException afterTimeoutExeption)
                {

                }
                client = channelFactory.CreateChannel(new EndpointAddress(uri));
                result = client.Execute(TimeSpan.FromMilliseconds(0));
            }
        }
예제 #14
0
        //创建Wcf 服务端代理
        private static T createProxyInstance <T>(Binding binding, EndpointAddress address, NetworkCredential credential)
        {
            Type objType = typeof(T);

            if (objType == null)
            {
                return(default(T));
            }
            try {
                object[] pars           = new object[] { binding, address };
                var      channelFactory = new System.ServiceModel.ChannelFactory <T>(binding, address);
                if (credential != null)
                {
                    channelFactory.Credentials.Windows.ClientCredential = credential;
                }

                System.ServiceModel.Description.ServiceEndpoint endPoint =
                    (System.ServiceModel.Description.ServiceEndpoint)MB.Util.MyReflection.Instance.InvokePropertyForGet(channelFactory, "Endpoint");


                object obj = typeof(System.ServiceModel.ServiceHost).Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior",
                                                                                             true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { false, Int32.MaxValue }, null, null);

                IEndpointBehavior dataSerializerBehavior = obj as IEndpointBehavior;
                endPoint.Behaviors.Add(dataSerializerBehavior);
                endPoint.Behaviors.Add(new EndpointMessageBehavior());

                var clientProxy = channelFactory.CreateChannel();
                if (clientProxy == null)
                {
                    throw new APPException(string.Format("根据类型:{0} 创建实例有误!", typeof(T).FullName));
                }

                return(clientProxy);
            }
            catch (APPException) {
                throw;
            }
            catch (Exception ex) {
                throw new MB.Util.APPException(string.Format("根据类型:{0}创建实例有误!", objType), APPMessageType.SysErrInfo, ex);
            }
        }
예제 #15
0
        public void IContextChannel_operationTimeoutSetGet_Ok()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();

            using (var server = new System.ServiceModel.ServiceHost(new SimpleService(), new Uri(address)))
            {
                server.AddServiceEndpoint(typeof(ISimpleService), binding, address);
                server.Open();
                Thread.Sleep(100);
                using (var channelFactory = new System.ServiceModel.ChannelFactory <ISimpleService>(binding))
                {
                    var client         = channelFactory.CreateChannel(new EndpointAddress(address));
                    var contextChannel = client as IContextChannel;
                    var newTimeout     = TimeSpan.FromSeconds(123);
                    contextChannel.OperationTimeout = newTimeout;
                    var timeout = contextChannel.OperationTimeout;
                    Assert.AreEqual(newTimeout, timeout);
                }
            }
        }
예제 #16
0
        public void IContextChannel_operationTimeoutSetGet_Ok()
        {
            var address = @"net.pipe://127.0.0.1/" + this.GetType().Name + "_" + MethodBase.GetCurrentMethod().Name;
            var binding = new NetNamedPipeBinding();
            using (var server = new System.ServiceModel.ServiceHost(new SimpleService(), new Uri(address)))
            {

                server.AddServiceEndpoint(typeof(ISimpleService), binding, address);
                server.Open();
                Thread.Sleep(100);
                using (var channelFactory = new System.ServiceModel.ChannelFactory<ISimpleService>(binding))
                {
                    var client = channelFactory.CreateChannel(new EndpointAddress(address));
                    var contextChannel = client as IContextChannel;
                    var newTimeout = TimeSpan.FromSeconds(123);
                    contextChannel.OperationTimeout = newTimeout;
                    var timeout = contextChannel.OperationTimeout;
                    Assert.AreEqual(newTimeout, timeout);

                }
            }
        }
 public IEnumerable <IFASBClientSelections> GetFASBClientSelectionsByClientID(int clientId)
 {
     try
     {
         BasicHttpBinding binding  = new BasicHttpBinding();
         EndpointAddress  endpoint = new EndpointAddress(
             new Uri(_dataAccessConfiguration.BaseUrl
                     + _dataAccessConfiguration.BaseService));
         ChannelFactory <IDataAccessService> channelFactory = new System.ServiceModel.ChannelFactory <IDataAccessService>(binding, endpoint);
         var serviceClient        = channelFactory.CreateChannel();
         var fASBClientSelections = serviceClient.GetFASBClientSelectionsByClientID(clientId);
         //IEnumerable<IFASBClientSelections> fASBClientSelections = serviceClient.GetFASBClientSelectionsByClientID(clientId);
         channelFactory.Close();
         return(fASBClientSelections);
     }
     catch (TimeoutException timeProblem)
     {
         Console.WriteLine("The service operation timed out. " + timeProblem.Message);
         Console.Read();
         throw new TimeoutException();
     }
     //catch (FaultException fault)
     //{
     //    Console.WriteLine("SampleFault fault occurred: {0}", fault.Detail.FaultMessage);
     //    Console.Read();
     //}
     catch (CommunicationException commProblem)
     {
         Console.WriteLine("There was a communication problem. " + commProblem.Message);
         Console.Read();
         throw new CommunicationException();
     }
     //finally
     //{
     //    channelFactory.Close();
     //}
 }
예제 #18
0
 public static T CreateChannelByName <T>(string endpointName, EndpointAddress address)
 {
     System.ServiceModel.ChannelFactory <T> factory = new System.ServiceModel.ChannelFactory <T>(endpointName, address);
     return(factory.CreateChannel());
 }