Exemplo n.º 1
0
    public static void ServiceContract_TypedProxy_DuplexCallback()
    {
        DuplexChannelFactory <IDuplexChannelService> factory = null;
        StringBuilder errorBuilder = new StringBuilder();
        Guid          guid         = Guid.NewGuid();

        try
        {
            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;

            DuplexChannelServiceCallback callbackService = new DuplexChannelServiceCallback();
            InstanceContext context = new InstanceContext(callbackService);

            factory = new DuplexChannelFactory <IDuplexChannelService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_DuplexCallback_Address));
            IDuplexChannelService serviceProxy = factory.CreateChannel();

            serviceProxy.Ping(guid);
            Guid returnedGuid = callbackService.CallbackGuid;

            if (guid != returnedGuid)
            {
                errorBuilder.AppendLine(String.Format("The sent GUID does not match the returned GUID. Sent: {0} Received: {1}", guid, returnedGuid));
            }

            factory.Close();
        }
        catch (Exception ex)
        {
            errorBuilder.AppendLine(String.Format("Unexpected exception was caught: {0}", ex.ToString()));
            for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException)
            {
                errorBuilder.AppendLine(String.Format("Inner exception: {0}", innerException.ToString()));
            }
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }

        if (errorBuilder.Length != 0)
        {
            Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: ServiceContract_TypedProxy_DuplexCallback FAILED with the following errors: {0}", errorBuilder));
        }
    }
Exemplo n.º 2
0
    public static void ServiceContract_TypedProxy_DuplexCallback()
    {
        NetTcpBinding binding = null;
        DuplexChannelFactory <IDuplexChannelService> factory = null;
        Guid guid = Guid.NewGuid();
        DuplexChannelServiceCallback callbackService = null;
        InstanceContext       context         = null;
        EndpointAddress       endpointAddress = null;
        IDuplexChannelService serviceProxy    = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;
            callbackService       = new DuplexChannelServiceCallback();
            context         = new InstanceContext(callbackService);
            endpointAddress = new EndpointAddress(Endpoints.Tcp_NoSecurity_DuplexCallback_Address);
            factory         = new DuplexChannelFactory <IDuplexChannelService>(context, binding, endpointAddress);
            serviceProxy    = factory.CreateChannel();

            // *** EXECUTE *** \\
            serviceProxy.Ping(guid);
            Guid returnedGuid = callbackService.CallbackGuid;

            // *** VALIDATE *** \\
            Assert.True(guid == returnedGuid, String.Format("The sent GUID does not match the returned GUID. Sent: {0} Received: {1}", guid, returnedGuid));

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
    public static async Task OperationContextCallbackAsyncFlow()
    {
        ChannelFactory <IDuplexChannelService> factory = null;
        IDuplexChannelService serviceProxy             = null;
        Guid guid = Guid.NewGuid();

        try
        {
            // *** SETUP *** \\
            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;
            DuplexChannelServiceCallback callbackService = new DuplexChannelServiceCallback();
            InstanceContext context         = new InstanceContext(callbackService);
            EndpointAddress endpointAddress = new EndpointAddress(Endpoints.Tcp_NoSecurity_DuplexCallback_Address);
            factory      = new DuplexChannelFactory <IDuplexChannelService>(context, binding, endpointAddress);
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            serviceProxy.Ping(guid);
            await callbackService.CallCompletedTask;

            // *** VALIDATE *** \\
            if (callbackService.Exception != null)
            {
                ExceptionDispatchInfo.Capture(callbackService.Exception).Throw();
            }

            // *** CLEANUP *** \\
            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }