void OnCall(object sender, EventArgs e) { MyContractClient proxy = new MyContractClient("TCP"); try { proxy.MethodWithError(); } catch (FaultException <DivideByZeroException> exception) { Trace.WriteLine("First call: " + exception.GetType() + " " + exception.Message); } catch (FaultException exception) { Trace.WriteLine("First call: " + exception.GetType() + " " + exception.Message); } catch (CommunicationException exception) { Trace.WriteLine("First call: " + exception.GetType() + " " + exception.Message); } try { proxy.MethodWithoutError(); } catch (Exception exception) { Trace.WriteLine("Second call: " + exception.GetType() + " " + exception.Message); } proxy.Close(); }
static void Main(string[] args) { using (var proxy = new MyContractClient()) { proxy.MyMethod(); proxy.MyMethod(); var sessionId = proxy.InnerChannel.SessionId; Trace.WriteLine("1. SessionId is " + sessionId); } using (var proxy = new MySessionContractClient()) { proxy.MyMethod(); proxy.MyMethod(); var sessionId = proxy.InnerChannel.SessionId; Trace.WriteLine("2. SessionId is " + sessionId); } using (var proxy = new MySingletonContractClient()) { proxy.MyMethod(); var sessionId = proxy.InnerChannel.SessionId; Trace.WriteLine("3. SessionId is " + sessionId); } using (var proxy = new MyOtherSingletonContractClient()) { proxy.MyOtherMethod(); var sessionId = proxy.InnerChannel.SessionId; Trace.WriteLine("4. SessionId is " + sessionId); } Console.ReadLine(); }
void OnCall(object sender,EventArgs e) { MyContractClient proxy = new MyContractClient("TCP"); try { proxy.MethodWithError(); } catch(FaultException<DivideByZeroException> exception) { Trace.WriteLine("First call: " + exception.GetType() + " " + exception.Message); } catch(FaultException exception) { Trace.WriteLine("First call: " + exception.GetType() + " " + exception.Message); } catch(CommunicationException exception) { Trace.WriteLine("First call: " + exception.GetType() + " " + exception.Message); } try { proxy.MethodWithoutError(); } catch(Exception exception) { Trace.WriteLine("Second call: " + exception.GetType() + " " + exception.Message); } proxy.Close(); }
static void Main(string[] args) { //var client = new MyContractClient("IMyContract"); // the first way to dispose IMyContract client = new MyContractClient(); client.MyMethod("test"); IDisposable disp = client as IDisposable; if (disp != null) { disp.Dispose(); } // the second way to dispose IMyContract proxy = new MyContractClient(); using (proxy as IDisposable) { proxy.MyMethod("test 2"); } using (var service = new MyContractClient()) { Console.WriteLine(service.MyMethod("test MyContractClient: ")); } using (var service = new MyOtherContractClient()) { Console.WriteLine(service.SomeMethod("test MyOtherContractClient: ")); } Console.ReadKey(); }
static void Main() { Trace.WriteLine("Client thread = " + Thread.CurrentThread.ManagedThreadId); MyClient client = new MyClient(); InstanceContext context = new InstanceContext(client); MyContractClient proxy = new MyContractClient(context); proxy.DoSomething(); proxy.Close(); }
static void Main() { Trace.WriteLine("Client thread = " + Thread.CurrentThread.ManagedThreadId); MyClient client = new MyClient(); InstanceContext context = new InstanceContext(client); MyContractClient proxy = new MyContractClient(context); proxy.DoSomething(); proxy.Close(); }
static void Main(string[] args) { using (var service = new MyContractClient()) { Console.WriteLine(service.MyMethod("test MyContractClient: ")); } using (var service = new MyOtherContractClient()) { Console.WriteLine(service.SomeMethod("test MyOtherContractClient: ")); } Console.ReadKey(); }
void OnCall(object sender, EventArgs e) { NetworkCredential credentials = new NetworkCredential(); credentials.Domain = m_DomainTextbox.Text; credentials.UserName = m_UserNameTextbox.Text; credentials.Password = m_PasswordTextBox.Text; MyContractClient proxy = new MyContractClient(); proxy.ClientCredentials.Windows.ClientCredential = credentials; proxy.ClientCredentials.Windows.AllowedImpersonationLevel = ImpersonationLevel; proxy.MyMethod(); proxy.Close(); }
static void Main(string[] args) { var uri = new Uri("net.tcp://localhost"); var binding = new NetTcpBinding(); var host = new ServiceHost(typeof(MyService), uri); host.AddServiceEndpoint(typeof(IMyContract), binding, ""); host.Open(); var callback = new MyCallbackClient(); var client = new MyContractClient(callback, binding, new EndpointAddress(uri)); var proxy = client.ChannelFactory.CreateChannel(); proxy.DoSomething(); // Printed in console: // Hi from server! // Hi from client! client.Close(); host.Close(); }