Beispiel #1
0
        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();
        }
Beispiel #2
0
      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();
      }
Beispiel #3
0
        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();
        }
Beispiel #4
0
      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();
      }
Beispiel #5
0
        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();
        }
Beispiel #6
0
    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();
    }