本文整理汇总了C#中System.ServiceModel.NetTcpBinding.Start方法的典型用法代码示例。如果您正苦于以下问题:C# NetTcpBinding.Start方法的具体用法?C# NetTcpBinding.Start怎么用?C# NetTcpBinding.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.NetTcpBinding
的用法示例。
在下文中一共展示了NetTcpBinding.Start方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartServer
public IDisposable StartServer()
{
var monitor = new ConnectionRateMonitor();
var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } };
var listener = binding.Start(this.ConnectArguments.CreateNetTcpAddress());
Console.WriteLine("Listening on {0} for {1}", listener.Uri, typeof(SimpleObject).Name);
listener.GetChannels()
.SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance)
.Subscribe(c =>
{
monitor.OnConnect();
c.GetMessages()
.Subscribe(
m =>
{
monitor.OnMessage();
var obj = m.GetBody<SimpleObject>();
},
ex => monitor.OnDisconnect(),
monitor.OnDisconnect);
});
monitor.Start();
return Disposable.Create(listener.Abort);
}
示例2: AcceptChannelTest
private static void AcceptChannelTest()
{
var binding = new NetTcpBinding();
var listener = binding.Start(address);
var connections = from channel in listener.GetChannels()
select new
{
Messages = channel.GetMessages(),
Response = channel.GetConsumer()
};
connections.Subscribe(item =>
{
item.Response.Publish(Message.CreateMessage(binding.MessageVersion, "Test", "Echo:" + "Connected"));
/*
(from message in channel.Messages
let input = message.GetBody<string>()
from response in new[] { Message.CreateMessage(version, "", "Echo:" + input) }
select response)
.Subscribe(channel.Response);
*/
item.Messages.Subscribe((message) =>
{
var input = message.GetBody<string>();
var output = Message.CreateMessage(binding.MessageVersion, "", "Echo:" + input);
item.Response.Publish(output);
});
});
}
示例3: Main
public static void Main(string args)
{
var binding = new NetTcpBinding {Security = {Mode = SecurityMode.None}};
var listener = binding.Start("net.tcp://localhost:8080/");
Console.WriteLine("Listening on " + listener.Uri);
listener.GetChannels()
.Subscribe(channel =>
channel.GetMessages()
.Subscribe(
m => Console.WriteLine("Message Received."),
ex => Console.WriteLine(ex.Message),
() => Console.WriteLine("Disconnected")));
}
示例4: GetMessages
public int GetMessages(int numberOfMessages)
{
var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } };
var listener = binding.Start(_address);
var tcs = new TaskCompletionSource<int>();
try
{
int count = 0;
var watch = new Stopwatch();
watch.Start();
listener.GetChannels().Subscribe(c =>
{
Console.WriteLine("Channel accepted");
c.GetMessages().Subscribe(m =>
{
// Console.WriteLine("Message received");
var bytes = m.GetBody<byte[]>();
// Console.WriteLine(Encoding.ASCII.GetString(bytes));
if (Interlocked.Increment(ref count) == numberOfMessages)
{
tcs.SetResult(numberOfMessages);
}
},
tcs.SetException);
}, tcs.SetException);
SendMessages(binding, numberOfMessages, _address);
Observable.Interval(TimeSpan.FromSeconds(1))
.TakeWhile(_ => count <= numberOfMessages)
.Subscribe(_ => Console.WriteLine("Received {0} messages at {1} messages/sec",
count,
count / watch.Elapsed.TotalSeconds));
tcs.Task.Wait(Defaults.LongTestWaitTime);
watch.Stop();
var seconds = watch.Elapsed.TotalSeconds;
Console.WriteLine("Received {0} messages in {1} seconds : {2} messages/sec",
count,
seconds,
count / seconds);
return count;
}
finally
{
listener.Abort();
}
}
示例5: StartService
public static IDisposable StartService()
{
//StartWcfService(address);
var binding = new NetTcpBinding() { };
binding.Security.Mode = SecurityMode.None;
var listener = binding.Start(Address);
listener
.OnMessage()
.OnGetOrder(c =>
{
Console.WriteLine(c.Name);
return new Order { Name = c.Name + ":Order" };
});
return Disposable.Create(listener.Abort);
}
示例6: ChannelConnectTest
private static void ChannelConnectTest()
{
var netTcpBibnding = new NetTcpBinding();
var listener = netTcpBibnding.Start(address);
listener.GetChannels().Subscribe(channel => {
channel.GetMessages().Subscribe(message =>
{
});
});
listener.OnConnect(channel =>
{
channel.Subscribe(message =>
{
var input = message.GetBody<string>();
var response = Message.CreateMessage(netTcpBibnding.MessageVersion, "", "Echo:" + input);
channel.Publish(message);
});
});
}
示例7: ChannelModelDispatcher
public static IDisposable ChannelModelDispatcher()
{
var binding = new NetTcpBinding() { };
binding.Security.Mode = SecurityMode.None;
var listener = binding.Start(Address);
var res = listener.OnMessage()
.Do(m => Console.WriteLine(m.Message.Headers.Action))
.Subscribe(
r =>
{
Customer c = r.Message.DecodeGetOrder();
Console.WriteLine(c.Name);
var output = new Order { Name = c.Name + ":Order" };
var response = output.EncodeGetOrderResponse(r.Message);
r.Publish(response);
}
);
return Disposable.Create(listener.Abort);
}
示例8: AcceptChannel
public void AcceptChannel()
{
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
var listener = binding.Start(address);
Scheduler.CurrentThread.Catch<Exception>((e) =>
{
Trace.WriteLine(e.Message);
return true;
});
try
{
listener
.OnConnect()
.Subscribe(
channel =>
{
var responses = channel.Select( message =>
{
var input = message.GetBody<string>();
return Message.CreateMessage(version, "", "Echo:" + input);
});
responses.Subscribe(channel.Publish);
//(from message in channel
// let input = message.GetBody<string>()
// select Message.CreateMessage(version, "", "Echo:" + input))
// .Subscribe(channel.Publish);
});
SendMessages();
}
finally
{
listener.Abort();
}
}
示例9: StartServer
public IDisposable StartServer()
{
var monitor = new ConnectionRateMonitor();
var binding = new NetTcpBinding { Security = { Mode = SecurityMode.None } };
var listener = binding.Start(_address);
Console.WriteLine("Listening on " + listener.Uri);
listener.GetChannels()
.SubscribeOn(System.Reactive.Concurrency.ThreadPoolScheduler.Instance)
.Subscribe(c =>
{
monitor.OnConnect();
c.GetMessages()
.Subscribe(
m => monitor.OnMessage(),
ex => monitor.OnDisconnect(),
monitor.OnDisconnect);
});
monitor.Start();
return Disposable.Create(listener.Abort);
}
示例10: MessageTest
private static void MessageTest()
{
NetTcpBinding b = new NetTcpBinding();
var listener = b.Start(address);
listener
.OnConnect()
.Do(c => Console.WriteLine("Channel accepted"))
.OnMessage()
.Do(m => Console.WriteLine("Received " + m.Message.Headers.Action))
.Subscribe(
r =>
{
var input = r.Message.GetBody<string>();
r.Publish(Message.CreateMessage(b.MessageVersion, "", "Echo:" + input));
r.Publish(Message.CreateMessage(b.MessageVersion, "", "Echo:" + input));
});
}