当前位置: 首页>>代码示例>>C#>>正文


C# WcfDuplexServiceCallback类代码示例

本文整理汇总了C#中WcfDuplexServiceCallback的典型用法代码示例。如果您正苦于以下问题:C# WcfDuplexServiceCallback类的具体用法?C# WcfDuplexServiceCallback怎么用?C# WcfDuplexServiceCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WcfDuplexServiceCallback类属于命名空间,在下文中一共展示了WcfDuplexServiceCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid

    public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
    {
        DuplexChannelFactory<IWcfDuplexService> factory = null;
        IWcfDuplexService duplexProxy = null;
        Guid guid = Guid.NewGuid();

        try
        {
            // *** SETUP *** \\
            NetHttpBinding binding = new NetHttpBinding();
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

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

            factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
            duplexProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            Task.Run(() => duplexProxy.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)duplexProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)duplexProxy, factory);
        }
    }
开发者ID:noodlese,项目名称:wcf,代码行数:35,代码来源:WebSocketTests.cs

示例2: RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid

    public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
    {
        DuplexChannelFactory<IWcfDuplexService> factory = null;
        Guid guid = Guid.NewGuid();

        NetHttpBinding binding = new NetHttpBinding();
        binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

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

        try
        {
            factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
            IWcfDuplexService duplexProxy = factory.CreateChannel();

            Task.Run(() => duplexProxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));
        }
        finally
        {
            if (factory != null && factory.State != CommunicationState.Closed)
            {
                factory.Abort();
            }
        }
    }
开发者ID:dmetzgar,项目名称:wcf,代码行数:29,代码来源:WebSocketTests.cs

示例3: NetTcpBinding_DuplexCallback_ReturnsXmlComplexType

    public static void NetTcpBinding_DuplexCallback_ReturnsXmlComplexType()
    {
        DuplexChannelFactory<IWcfDuplexService_Xml> factory = null;
        NetTcpBinding binding = null;
        WcfDuplexServiceCallback callbackService = null;
        InstanceContext context = null;
        IWcfDuplexService_Xml serviceProxy = null;
        Guid guid = Guid.NewGuid();

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

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

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

            serviceProxy.Ping_Xml(guid);
            XmlCompositeTypeDuplexCallbackOnly returnedType = callbackService.XmlCallbackGuid;

            // validate response
            Assert.True((guid.ToString() == returnedType.StringValue), String.Format("The Guid to string value sent was not the same as what was returned.\nSent: {0}\nReturned: {1}", guid.ToString(), returnedType.StringValue));

            ((ICommunicationObject)serviceProxy).Close();
            factory.Close();
        }
        finally
        {
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:34,代码来源:DataContractTests.4.1.0.cs

示例4: DuplexClientBaseOfT_OverNetTcp_Synchronous_Call

    public static void DuplexClientBaseOfT_OverNetTcp_Synchronous_Call()
    {
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        Guid guid = Guid.NewGuid();

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

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

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address));
            IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel();

            // Ping on another thread.
            Task.Run(() => proxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            Assert.True(guid == returnedGuid, 
                string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid)); 

            ((ICommunicationObject)duplexService).Close();
        }
        finally
        {
            if (duplexService != null && duplexService.State != CommunicationState.Closed)
            {
                duplexService.Abort();
            }
        }
    }
开发者ID:huoxudong125,项目名称:wcf,代码行数:33,代码来源:DuplexClientBaseTests.cs

示例5: CreateChannel_EmptyEndpointAddress_AsString_ThrowsUriFormat

 public static void CreateChannel_EmptyEndpointAddress_AsString_ThrowsUriFormat()
 {
     WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
     InstanceContext context = new InstanceContext(callback);
     Binding binding = new NetTcpBinding();
     Assert.Throws<UriFormatException>(() =>
     {
         DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, string.Empty);
     });
 }
开发者ID:noodlese,项目名称:wcf,代码行数:10,代码来源:DuplexChannelFactoryTest.cs

示例6: CreateChannel_ExpectedNetTcpScheme_InvalidScheme_ThrowsUriFormat

 // valid address, but the scheme is incorrect
 public static void CreateChannel_ExpectedNetTcpScheme_InvalidScheme_ThrowsUriFormat()
 {
     WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
     InstanceContext context = new InstanceContext(callback);
     Binding binding = new NetTcpBinding();
     Assert.Throws<ArgumentException>("via", () =>
     {
         DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, "qwerty://not-the-right-scheme");
         factory.CreateChannel();
     });
 }
开发者ID:wl0240407225,项目名称:wcf,代码行数:12,代码来源:DuplexChannelFactoryTest.cs

示例7: DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation

    public static void DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation()
    {
#if FULLXUNIT_NOTSUPPORTED
        bool root_Certificate_Installed = Root_Certificate_Installed();
        if (!root_Certificate_Installed)
        {
            Console.WriteLine("---- Test SKIPPED --------------");
            Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
            Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
            return;
        }
#endif
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        IWcfDuplexService proxy = null;

        try
        {
            // *** SETUP *** \\
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);

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

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Https_DefaultBinding_Address));

            // *** EXECUTE *** \\
            var exception = Assert.Throws<InvalidOperationException>(() =>
            {
                proxy = duplexService.ChannelFactory.CreateChannel();
            });

            // *** VALIDATE *** \\
            // Can't compare the entire exception message - .NET Native doesn't necessarily output the entire message, just params
            // "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it"
            Assert.True(exception.Message.Contains("BasicHttpBinding"));

            Assert.Throws<CommunicationObjectFaultedException>(() =>
            {
                // You can't gracefully close a Faulted CommunicationObject, so we should make sure it throws here too
                ((ICommunicationObject)duplexService).Close();
            });

            // *** CLEANUP *** \\
            // proxy will be null here so can't close.
            // duplexService is closed prior to this as part of an assert to verify an expected exception.
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, duplexService);
        }
    }
开发者ID:weshaggard,项目名称:wcf,代码行数:52,代码来源:DuplexClientBaseTests.cs

示例8: TransportUsageAlways_WebSockets_Synchronous_Call

    public static void TransportUsageAlways_WebSockets_Synchronous_Call()
    {
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        Guid guid = Guid.NewGuid();

        try
        {
            NetHttpBinding binding = new NetHttpBinding();
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;

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

            var uri = new Uri(Endpoints.HttpBaseAddress_NetHttpWebSocket);
            UriBuilder builder = new UriBuilder(Endpoints.HttpBaseAddress_NetHttpWebSocket);
            switch (uri.Scheme.ToLowerInvariant())
            {
                case "http":
                    builder.Scheme = "ws";
                    break;
                case "https":
                    builder.Scheme = "wss";
                    break;
            }

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(builder.Uri));
            IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel();

            // Ping on another thread.
            proxy.Ping(guid);
            //Task.Run(() => proxy.Ping(guid));
            Guid returnedGuid = callbackService.CallbackGuid;

            Assert.True(guid == returnedGuid,
                string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));

            ((ICommunicationObject)duplexService).Close();
        }
        finally
        {
            if (duplexService != null && duplexService.State != CommunicationState.Closed)
            {
                duplexService.Abort();
            }
        }
    }
开发者ID:yuanyeXu,项目名称:wcf,代码行数:46,代码来源:WebSocketNetHttpBindingTests.cs

示例9: DuplexClientBaseOfT_OverNetTcp_Call

    public static void DuplexClientBaseOfT_OverNetTcp_Call()
    {
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        StringBuilder errorBuilder = new StringBuilder();
        Guid guid = Guid.NewGuid();

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

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

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address));
            IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel();

            // Ping on another thread.
            Task.Run(() => proxy.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));
            }

            duplexService.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 (duplexService != null && duplexService.State != CommunicationState.Closed)
            {
                duplexService.Abort();
            }
        }

        Assert.True(errorBuilder.Length == 0, string.Format("Test Scenario: DuplexClientBaseOfT_OverNetTcp_Call FAILED with the following errors: {0}", errorBuilder));
    }
开发者ID:shijiaxing,项目名称:wcf,代码行数:46,代码来源:DuplexClientBaseTests.cs

示例10: CreateChannel_EndpointAddress_Null_Throws

    public static void CreateChannel_EndpointAddress_Null_Throws()
    {
        WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
        InstanceContext context = new InstanceContext(callback);
        Binding binding = new NetTcpBinding();
        EndpointAddress remoteAddress = null;

        DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, remoteAddress);
        try {
            Assert.Throws<InvalidOperationException>(() =>
               {
                   factory.Open();
                   factory.CreateChannel();
               });
        }
        finally
        { 
            factory.Abort();
        }
    }
开发者ID:wl0240407225,项目名称:wcf,代码行数:20,代码来源:DuplexChannelFactoryTest.cs

示例11: DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation

    public static void DuplexClientBaseOfT_OverHttp_Call_Throws_InvalidOperation()
    {
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        Guid guid = Guid.NewGuid();

        try
        {
            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); 

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

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Https_DefaultBinding_Address));

            var exception = Assert.Throws<InvalidOperationException>(() => 
            { 
                IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel();
            });

            // Can't compare the entire exception message - .NET Native doesn't necessarily output the entire message, just params
            // "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it"
            Assert.True(exception.Message.Contains("BasicHttpBinding"));

            Assert.Throws<CommunicationObjectFaultedException>(() => 
            {
                // You can't gracefully close a Faulted CommunicationObject, so we should make sure it throws here too
                ((ICommunicationObject)duplexService).Close();
            }); 
        }
        finally
        {
            if (duplexService != null && duplexService.State != CommunicationState.Closed)
            {
                duplexService.Abort();
            }
        }
    }
开发者ID:huoxudong125,项目名称:wcf,代码行数:37,代码来源:DuplexClientBaseTests.cs

示例12: DuplexClientBaseOfT_OverNetTcp_Synchronous_Call

    public static void DuplexClientBaseOfT_OverNetTcp_Synchronous_Call()
    {
        DuplexClientBase<IWcfDuplexService> duplexService = null;
        IWcfDuplexService proxy = null;
        Guid guid = Guid.NewGuid();

        try
        {
            // *** SETUP *** \\
            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;

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

            duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address));
            proxy = duplexService.ChannelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Ping on another thread.
            Task.Run(() => proxy.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 *** \\
            ((ICommunicationObject)duplexService).Close();
            ((ICommunicationObject)proxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)proxy, (ICommunicationObject)duplexService);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:37,代码来源:DuplexClientBaseTests.4.1.0.cs

示例13: IOperationBehavior_Methods_AreCalled

    public static void IOperationBehavior_Methods_AreCalled()
    {
        DuplexClientBase<ICustomOperationBehaviorDuplexService> duplexService = null;
        ICustomOperationBehaviorDuplexService proxy = null;

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

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

        duplexService = new MyDuplexClientBase<ICustomOperationBehaviorDuplexService>(context, binding, new EndpointAddress(FakeAddress.TcpAddress));
        proxy = duplexService.ChannelFactory.CreateChannel();

        // Wait to validate until the process has been given a reasonable time to complete.
        Task[] taskCollection = { MyOperationBehavior.validateMethodTcs.Task, MyOperationBehavior.addBindingParametersMethodTcs.Task, MyOperationBehavior.applyClientBehaviorMethodTcs.Task };
        bool waitAll = Task.WaitAll(taskCollection, 250);

        Assert.True(MyOperationBehavior.errorBuilder.Length == 0, "Test case FAILED with errors: " + MyOperationBehavior.errorBuilder.ToString());
        Assert.True(waitAll, "None of the IOperationBehavior methods were called.");

        ((ICommunicationObject)proxy).Close();
        ((ICommunicationObject)duplexService).Close();
    }
开发者ID:weshaggard,项目名称:wcf,代码行数:24,代码来源:OperationBehaviorTest.cs

示例14: CreateChannel_Using_Http_NoSecurity

    public static void CreateChannel_Using_Http_NoSecurity()
    {
        WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
        InstanceContext context = new InstanceContext(callback);
        Binding binding = new NetHttpBinding(BasicHttpSecurityMode.None);
        EndpointAddress endpoint = new EndpointAddress(FakeAddress.HttpAddress);
        DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, endpoint);

        // Can't cast to IDuplexSessionChannel to IRequestChannel on http
        var exception = Assert.Throws<InvalidCastException>(() =>
        {
            factory.CreateChannel();
        });

        // Can't check that the InvalidCastException message as .NET Native only reports this message for all InvalidCastExceptions:
        // "System.InvalidCastException: Arg_InvalidCastException"
    }
开发者ID:wl0240407225,项目名称:wcf,代码行数:17,代码来源:DuplexChannelFactoryTest.cs

示例15: CreateChannel_Using_Http_NoSecurity

 public static void CreateChannel_Using_Http_NoSecurity()
 {
     WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
     InstanceContext context = new InstanceContext(callback);
     Binding binding = new NetHttpBinding(BasicHttpSecurityMode.None);
     EndpointAddress endpoint = new EndpointAddress(FakeAddress.HttpAddress);
     DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, endpoint);
     factory.CreateChannel();
 }
开发者ID:noodlese,项目名称:wcf,代码行数:9,代码来源:DuplexChannelFactoryTest.cs


注:本文中的WcfDuplexServiceCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。