本文整理汇总了C#中DuplexChannelFactory.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# DuplexChannelFactory.Abort方法的具体用法?C# DuplexChannelFactory.Abort怎么用?C# DuplexChannelFactory.Abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DuplexChannelFactory
的用法示例。
在下文中一共展示了DuplexChannelFactory.Abort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
示例2: ServiceContract_TypedProxy_AsyncTask_CallbackReturn
public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn()
{
DuplexChannelFactory<IWcfDuplexTaskReturnService> factory = null;
Guid guid = Guid.NewGuid();
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback();
InstanceContext context = new InstanceContext(callbackService);
try
{
factory = new DuplexChannelFactory<IWcfDuplexTaskReturnService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address));
IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel();
Task<Guid> task = serviceProxy.Ping(guid);
Guid returnedGuid = task.Result;
Assert.Equal(guid, returnedGuid);
factory.Close();
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
}
示例3: 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();
}
}
示例4: worker
internal static void worker(int loop, string name, InstanceContext context)
{
//ThreadPool.QueueUserWorkItem(delegate
//{
DuplexChannelFactory<ITest> factory = null;
ITest channel = null;
try
{
factory = new DuplexChannelFactory<ITest>(context, name);
channel = factory.CreateChannel();
using (var scope = new OperationContextScope((IContextChannel)channel))
{
OperationContext.Current.OutgoingMessageHeaders.ReplyTo = ((IClientChannel)channel).LocalAddress;
// action
channel.Ping("Hello, " + loop.ToString());
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(string.Format("[{0}, {1}]: D O N E, tid={2}", loop, name, Thread.CurrentThread.GetHashCode()));
Console.ResetColor();
Console.WriteLine("\n+++ press any key to close this channel +++\n");
Console.ReadLine();
}
((IChannel)channel).Close();
factory.Close();
}
catch (Exception ex)
{
if (channel != null) ((IChannel)channel).Abort();
if (factory != null) factory.Abort();
Console.WriteLine(ex.Message);
}
//});
}
示例5: ServiceContract_TypedProxy_DuplexCallback
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));
}
}
示例6: Main
static void Main()
{
_handler += Handler;
SetConsoleCtrlHandler(_handler, true);
ClientProcessor = new ClientProcessor();
var instanceContext = new InstanceContext(new BombermanCallbackService(ClientProcessor));
Binding binding = new NetTcpBinding(SecurityMode.None);
DuplexChannelFactory<IBombermanService> factory = new DuplexChannelFactory<IBombermanService>(instanceContext, binding, new EndpointAddress(
new Uri(string.Concat("net.tcp://", ConfigurationManager.AppSettings["MachineName"], ":7900/BombermanCallbackService"))));
Proxy = factory.CreateChannel();
Console.WriteLine("--------------------------------------");
Console.WriteLine("-------- Welcome to Bomberman --------");
Console.WriteLine("--------------------------------------\n\n");
do
{
Console.WriteLine("Type your player name :\n");
Username = Console.ReadLine();
ConnectUser(Username);
ClientProcessor.Username = Username;
} while (ErrorConnection);
Log.Initialize(@"D:\Temp\BombermanLogs", "Client_" + Username + ".log");
Log.WriteLine(Log.LogLevels.Info, "Logged at " + DateTime.Now.ToShortTimeString());
bool stop = false;
while (!stop)
{
ConsoleKeyInfo keyboard = Console.ReadKey();
switch (keyboard.Key)
{
//s
case ConsoleKey.S:
StartGame();
break;
case ConsoleKey.UpArrow:
MoveTo(ActionType.MoveUp);
break;
case ConsoleKey.LeftArrow:
MoveTo(ActionType.MoveLeft);
break;
case ConsoleKey.RightArrow:
MoveTo(ActionType.MoveRight);
break;
case ConsoleKey.DownArrow:
MoveTo(ActionType.MoveDown);
break;
case ConsoleKey.X: // SinaC: never leave a while(true) without an exit condition
stop = true;
break;
}
}
// SinaC: Clean properly factory
try
{
factory.Close();
}
catch (Exception ex)
{
Log.WriteLine(Log.LogLevels.Warning, "Exception:{0}", ex);
factory.Abort();
}
}