static void Main(string[] args) { //ChannelFactory<IEvalService> factory = new ChannelFactory<IEvalService>("BasicHttpBinding_IEvalService"); //IEvalService channel = factory.CreateChannel(); var channel = new EvalServiceClient("BasicHttpBinding_IEvalService"); try { channel.SubmitEval(new Eval { Comments = "hepp", Submitter = "hopp", Timesent = DateTime.Now }); foreach (var item in channel.GetEvals()) { Console.WriteLine(item.Comments + " " + item.Submitter + " " + item.Timesent); } Console.ReadKey(); channel.Close(); } catch (TimeoutException ex) { Console.WriteLine(ex.Message); } //((IClientChannel)channel).Close(); }
static void WorkViaGeneratedProxy() { Console.WriteLine("Retrieving endpoints vis MEX..."); ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IEvalService), new EndpointAddress("http://localhost:8080/evals/mex")); Console.WriteLine("Endpoints retrieved"); foreach (var endpoint in endpoints) { Console.WriteLine(endpoint.Address.Uri); var client = new EvalServiceClient(endpoint.Binding, endpoint.Address); try { WorkWithService(client); client.Close(); } catch (FaultException fe) { Console.WriteLine($"Fault exception: {fe.GetType()}"); client.Abort(); } catch (CommunicationException ce) { Console.WriteLine($"Communication exception: {ce.GetType()}"); client.Abort(); } catch (TimeoutException te) { Console.WriteLine($"Timeout exception: {te.GetType()}"); client.Abort(); } } }
static void Main(string[] args) { EvalServiceClient evalServiceClient = new EvalServiceClient(); Eval eval; eval = new Eval { Comments = "CommentsField1", Submitter = "Submitter1", TimeSubmitted = DateTime.Now }; evalServiceClient.SubmitEval(eval); eval = new Eval { Comments = "CommentsField2", Submitter = "Submitter2", TimeSubmitted = DateTime.Now }; evalServiceClient.SubmitEval(eval); eval = new Eval { Comments = "CommentsField3", Submitter = "Submitter3", TimeSubmitted = DateTime.Now }; evalServiceClient.SubmitEval(eval); Eval[] evals = evalServiceClient.GetEvals(); foreach (Eval e in evals) { Console.WriteLine("{0}\t{1}\t{2}", e.Id, e.Submitter, e.TimeSubmitted); } evalServiceClient.Close(); Console.ReadLine(); }
static void Main(string[] args) { #region example using ChannelFactory<T> directly //ChannelFactory<IEvalService> cf = // new ChannelFactory<IEvalService>("WSHttpBinding_IEvalService"); //IEvalService channel = cf.CreateChannel(); #endregion Console.WriteLine("Retrieving endpoints via MEX..."); ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IEvalService), new EndpointAddress("http://localhost:8080/evals/mex")); foreach (ServiceEndpoint se in endpoints) { EvalServiceClient channel = new EvalServiceClient(se.Binding, se.Address); try { EvalServiceLibrary.Eval eval = new EvalServiceLibrary.Eval("Aaron", "I'm really liking this"); channel.SubmitEval(eval); channel.SubmitEval(eval); List<EvalServiceLibrary.Eval> evals = channel.GetEvals(); Console.WriteLine("Number of evals: {0}", evals.Count); #region async example //channel.GetEvalsCompleted += new EventHandler<GetEvalsCompletedEventArgs>(channel_GetEvalsCompleted); //channel.GetEvalsAsync(); //Console.WriteLine("Waiting..."); //Console.ReadLine(); #endregion channel.Close(); } catch (FaultException fe) { Console.WriteLine("FaultException handler: {0}", fe.GetType()); channel.Abort(); } catch (CommunicationException ce) { Console.WriteLine("CommunicationException handler: {0}", ce.GetType()); channel.Abort(); } catch (TimeoutException te) { Console.WriteLine("TimeoutException handler: {0}", te.GetType()); channel.Abort(); } } }
static void Main(string[] args) { #region example using ChannelFactory<T> directly //ChannelFactory<IEvalService> cf = // new ChannelFactory<IEvalService>("WSHttpBinding_IEvalService"); //IEvalService channel = cf.CreateChannel(); #endregion Console.WriteLine("Retrieving endpoints via MEX..."); ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IEvalService), new EndpointAddress("http://localhost:8080/evals/mex")); foreach (ServiceEndpoint se in endpoints) { EvalServiceClient channel = new EvalServiceClient(se.Binding, se.Address); try { EvalServiceLibrary.Eval eval = new EvalServiceLibrary.Eval("Aaron", "I'm really liking this"); channel.SubmitEval(eval); channel.SubmitEval(eval); List <EvalServiceLibrary.Eval> evals = channel.GetEvals(); Console.WriteLine("Number of evals: {0}", evals.Count); #region async example //channel.GetEvalsCompleted += new EventHandler<GetEvalsCompletedEventArgs>(channel_GetEvalsCompleted); //channel.GetEvalsAsync(); //Console.WriteLine("Waiting..."); //Console.ReadLine(); #endregion channel.Close(); } catch (FaultException fe) { Console.WriteLine("FaultException handler: {0}", fe.GetType()); channel.Abort(); } catch (CommunicationException ce) { Console.WriteLine("CommunicationException handler: {0}", ce.GetType()); channel.Abort(); } catch (TimeoutException te) { Console.WriteLine("TimeoutException handler: {0}", te.GetType()); channel.Abort(); } } }
public static void Main(string[] args) { // var cf = new ChannelFactory<IEvalServiceChannel>("NetNamedPipeBinding_IEvalService"); // var channel = cf.CreateChannel(); var endpoints = MetadataResolver.Resolve( typeof(IEvalService), new EndpointAddress("http://localhost:8080/evals/mex")); foreach (var se in endpoints) { var channel = new EvalServiceClient(se.Binding, se.Address); // var channel = new EvalServiceClient("WSHttpBinding_IEvalService"); try { var eval = new Eval(); eval.Submitter = "Howard"; eval.Timesent = DateTime.Now; eval.Comments = "I'm thinking this..."; channel.SubmitEval(eval); channel.SubmitEval(eval); var evals = channel.GetEvals(); Console.WriteLine("Number of evals: {0}", evals.Count); channel.Close(); } catch (FaultException fe) { Console.WriteLine("FaultException handler: {0}", fe.GetType()); channel.Abort(); } catch (CommunicationException ce) { Console.WriteLine("CommunicationException handler: {0}", ce.GetType()); channel.Abort(); } catch (TimeoutException te) { Console.WriteLine("TimeoutException handler: {0}", te.GetType()); channel.Abort(); } } Console.ReadLine(); }
static void Main(string[] args) { // create a factory /////////////////////////////////////////////////// // factory by name ChannelFactory<IEvalService> factory1 = new ChannelFactory<IEvalService>("BasicHttpBinding_IEvalService"); // factory by endpoint ChannelFactory<IEvalService> factory2 = new ChannelFactory<IEvalService>(new WSHttpBinding(), "http://localhost:8080/evals/wsconfig"); // channel - basic, hidden IClientChannel /////////////////////////////////////////////////// IEvalService channel1 = factory1.CreateChannel(); try { channel1.GetEvals(); Eval eval = new Eval(); eval.Submitter = "Jay"; eval.Timesent = DateTime.Now; eval.Comments = "One eval to rule them alll!!!!!!!!!"; channel1.SubmitEval(eval); channel1.SubmitEval(eval); Console.ReadLine(); ((IClientChannel)channel1).Close(); } catch (Exception) { ((IClientChannel)channel1).Abort(); } // channel client - integrated IClientChannel /////////////////////////////////////////////////// ChannelFactory<IEvalServiceChannel> factory3 = new ChannelFactory<IEvalServiceChannel>("BasicHttpBinding_IEvalService"); IEvalServiceChannel channel2 = factory3.CreateChannel(); try { Eval[] evals = channel2.GetEvals(); Console.WriteLine("Number of evals: {0}", evals.Length); Console.ReadLine(); channel2.Close(); } catch (Exception) { channel2.Abort(); } // proxy client /////////////////////////////////////////////////// EvalServiceClient client1 = new EvalServiceClient("BasicHttpBinding_IEvalService"); try { Eval[] evals = client1.GetEvals(); Console.WriteLine("Number of evals: {0}", evals.Length); Console.ReadLine(); client1.Close(); } catch (Exception) { client1.Abort(); } }
static void Main(string[] args) { //var cf = new ChannelFactory<IEvalServiceChannel>("End4"); //var service = cf.CreateChannel(); var endpoints = MetadataResolver.Resolve(typeof (IEvalService), new EndpointAddress("http://localhost:8085/evals/mex")); foreach (var endpoint in endpoints) { var service = new EvalServiceClient(endpoint.Binding, endpoint.Address); try { var newEval = new Eval { Comments = "Testing", Submitter = "Rafael", Timesent = DateTime.Now }; service.SubmitEval(newEval); service.SubmitEval(newEval); //var evals = service.GetEvals(); service.GetEvalsCompleted += service_GetEvalsCompleted; service.GetEvalsAsync(); Console.WriteLine("Waiting..."); //Thread.Sleep(10000); Console.WriteLine("Waiting More..."); //Console.ReadLine(); //foreach (var eval in evals) //{ // Console.WriteLine(eval.Submitter + " " + eval.Comments); //} service.Close(); } catch (FaultException exception) { Console.WriteLine("Ops... Something went wrong"); Console.WriteLine(exception); service.Abort(); } catch (CommunicationException exception) { Console.WriteLine("Ops... Something went wrong"); Console.WriteLine(exception); service.Abort(); } catch (TimeoutException exception) { Console.WriteLine("Ops... Something went wrong"); Console.WriteLine(exception); service.Abort(); } Console.ReadLine(); } }