本文整理汇总了C#中DuplexChannelFactory.CreateChannel方法的典型用法代码示例。如果您正苦于以下问题:C# DuplexChannelFactory.CreateChannel方法的具体用法?C# DuplexChannelFactory.CreateChannel怎么用?C# DuplexChannelFactory.CreateChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DuplexChannelFactory
的用法示例。
在下文中一共展示了DuplexChannelFactory.CreateChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connect
public void connect(String url, IAudioServiceCallBack callback, EventHandler openedEvt = null, EventHandler faultEvt = null) //url = "net.tcp://localhost:8080/AudioService"
{
try
{
duplex = new DuplexChannelFactory<IAudioService>(callback, new NetTcpBinding(),
new EndpointAddress(url));
service = duplex.CreateChannel();
channel = (ICommunicationObject)service;
IClientChannel c = (IClientChannel)channel;
c.OperationTimeout = TimeSpan.FromSeconds(5);
channel.Opened += new EventHandler(delegate(object o, EventArgs e)
{
Console.WriteLine("Connection ok!");
});
if(openedEvt != null)
channel.Opened += openedEvt;
if(faultEvt != null)
channel.Faulted += faultEvt;
channel.Faulted += new EventHandler(delegate(object o, EventArgs e)
{
Console.WriteLine("Connection lost");
});
}
catch (Exception e)
{
Console.WriteLine("Connection error: " + e.Message);
}
}
示例2: OrationiSlave
public OrationiSlave()
{
Binding binding = new NetTcpBinding(SecurityMode.None);
EndpointAddress defaultEndpointAddress = new EndpointAddress("net.tcp://localhost:57344/Orationi/Master/v1/");
EndpointAddress discoveredEndpointAddress = DiscoverMaster();
ContractDescription contractDescription = ContractDescription.GetContract(typeof(IOrationiMasterService));
ServiceEndpoint serviceEndpoint = new ServiceEndpoint(contractDescription, binding, discoveredEndpointAddress ?? defaultEndpointAddress);
var channelFactory = new DuplexChannelFactory<IOrationiMasterService>(this, serviceEndpoint);
try
{
channelFactory.Open();
}
catch (Exception ex)
{
channelFactory?.Abort();
}
try
{
_masterService = channelFactory.CreateChannel();
_communicationObject = (ICommunicationObject)_masterService;
_communicationObject.Open();
}
catch (Exception ex)
{
if (_communicationObject != null && _communicationObject.State == CommunicationState.Faulted)
_communicationObject.Abort();
}
}
示例3: submitButton_Click
private void submitButton_Click(object sender, RoutedEventArgs e)
{
var login = loginTextBox.Text;
var pass = passwordTextBox.Password;
Action<String> status = s => {
statusLabel.Content = s;
statusLabel.ToolTip = s;
};
try {
channelFactory = new DuplexChannelFactory<IService>(new ClientImplementation(_MainWindow), "DnDServiceEndPoint");
server = channelFactory.CreateChannel();
if (server.Login(login, pass)) {
_MainWindow.InitializeServer(channelFactory, server);
this.DialogResult = true;
} else {
statusLabel.Content = "Login lub hasło nie są poprawne!";
return;
}
} catch (Exception ex) {
statusLabel.Content = "Nastąpił błąd! Spróbuj ponownie";
System.IO.StreamWriter file = new System.IO.StreamWriter("log.txt");
file.WriteLine(ex.ToString());
file.Close();
return;
}
this.Close();
}
示例4: MainWindow
public MainWindow()
{
InitializeComponent();
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:31337/BesiegedServer/BesiegedMessage");
DuplexChannelFactory<IBesiegedServer> duplexChannelFactory = new DuplexChannelFactory<IBesiegedServer>(m_Client, new WSDualHttpBinding(), endpointAddress);
m_BesiegedServer = duplexChannelFactory.CreateChannel();
// Subscribe in a separate thread to preserve the UI thread
Task.Factory.StartNew(() =>
{
CommandConnect commandConnect = new CommandConnect();
m_BesiegedServer.SendMessage(commandConnect.ToXml());
});
Task.Factory.StartNew(() =>
{
while (true)
{
Command command = m_Client.MessageQueue.Take();
ProcessMessage(command);
}
}, TaskCreationOptions.LongRunning);
GameLobbyCollection = new ObservableCollection<CommandNotifyGame>();
DataContext = this;
}
示例5: RegisterViewModel
public RegisterViewModel()
{
var channelFactory = new DuplexChannelFactory<IChattingService>(new ClientService(), "ChattingServiceEndPoint");
_server = channelFactory.CreateChannel();
Register = new RelayCommand(OnRegister, () => !(string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password)));
ClearCommand = new RelayCommand(OnClear);
}
示例6: ConnectIpc
public static void ConnectIpc(IServiceRemotingCallback serviceRemotingCallback)
{
InstanceContext instanceContext = new InstanceContext(serviceRemotingCallback);
PipeFactory = new DuplexChannelFactory<IServiceRemoting>(instanceContext, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/BitCollectors.PlinkService/PlinkService"));
RemotingObject = PipeFactory.CreateChannel();
}
示例7: MonitorForm_Load
//其他成员
private void MonitorForm_Load(object sender, EventArgs e)
{
string header = string.Format("{0, -13}{1, -22}{2}", "Client", "Time", "Event");
this.listBoxExecutionProgress.Items.Add(header);
_syncContext = SynchronizationContext.Current;
_callbackInstance = new InstanceContext(new CalculatorCallbackService());
_channelFactory = new DuplexChannelFactory<ICalculator>(_callbackInstance, "calculatorservice");
EventMonitor.MonitoringNotificationSended += ReceiveMonitoringNotification;
this.Disposed += delegate
{
EventMonitor.MonitoringNotificationSended -= ReceiveMonitoringNotification;
_channelFactory.Close();
};
for (int i = 0; i < 2; i++)
{
ThreadPool.QueueUserWorkItem(state =>
{
int clientId = Interlocked.Increment(ref _clientId);
EventMonitor.Send(clientId, EventType.StartCall);
ICalculator proxy = _channelFactory.CreateChannel();
using (OperationContextScope contextScope = new OperationContextScope(proxy as IContextChannel))
{
MessageHeader<int> messageHeader = new MessageHeader<int>(clientId);
OperationContext.Current.OutgoingMessageHeaders.Add(messageHeader.GetUntypedHeader(EventMonitor.CientIdHeaderLocalName, EventMonitor.CientIdHeaderNamespace));
proxy.Add(1, 2);
}
EventMonitor.Send(clientId, EventType.EndCall);
}, null);
}
}
示例8: Main
static void Main(string[] args)
{
var fact = new ChannelFactory<IDeviceManagerService>("deviceEndpoint");
InstanceContext callback = new InstanceContext(new ServiceCallback());
var dup = new DuplexChannelFactory<ICardReaderEventsSubscribe>(callback, "dupSocket");
var cardReaderSub = dup.CreateChannel();
var cha = fact.CreateChannel();
using (fact)
{
var devices = cha.GetAllDevices();
//cha.Open(new devices[0].FullSerialNumber );
}
Console.WriteLine("try a new");
Console.ReadKey();
Console.WriteLine("REading duplex");
cardReaderSub.SubscribeToCardSwipeByhost("Local");
Console.ReadKey();
var fact1 = new ChannelFactory<IDeviceManagerService>("deviceEndpoint");
var cha1 = fact1.CreateChannel();
using (fact1)
{
var devices = cha1.GetAllDevices();
}
}
示例9: Connect
/// <summary>
/// Connect to game server
/// </summary>
/// <param name="IP"></param>
/// <returns></returns>
public bool Connect(String IP)
{
// Create a pipeFactory
DuplexChannelFactory<IMessage> pipeFactory =
new DuplexChannelFactory<IMessage>(
new InstanceContext(this),
new NetTcpBinding(),
//new EndpointAddress(String.Format("net.tcp://{0}:8000/GameServer", IP)));
new EndpointAddress(String.Format("net.tcp://{0}:8000/GameServer", "localhost")));
try
{
// Creating the communication channel
pipeProxy = pipeFactory.CreateChannel();
// register for events
pipeProxy.Subscribe();
// join the game
myID = pipeProxy.join(me.Username, me.money, me.numOfGames, me.ID);
if (pipeProxy.runningGame())
{
pipeProxy.resetGame();
}
return true;
}
catch (Exception e)
{
return false;
}
}
示例10: StartP2PClient
private void StartP2PClient( )
{
string s = ConfigurationManager.AppSettings["IsSupportGroup"];
if (s.Equals("no", StringComparison.OrdinalIgnoreCase))
{
return;
}
InstanceContext context = new InstanceContext(new P2PChatService());
DuplexChannelFactory<IP2PChatService> factory = new DuplexChannelFactory<IP2PChatService>(context,"p2p", new EndpointAddress("net.p2p://" + groupId));
channel = factory.CreateChannel();
clients.Add(groupId, this);
new Thread(new ThreadStart(() =>
{
try
{
channel.Join();
}
catch (Exception ex)
{
MyLogger.Logger.Error("进入群组聊天室时出错",ex);
}
})).Start();
}
示例11: MainWindow
public MainWindow()
{
try
{
//Center the window on startup
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
InitializeComponent();
createGrid();
// Configure the Endpoint details
DuplexChannelFactory<ITileBag> channel = new DuplexChannelFactory<ITileBag>(this, "TileBag");
// Activate a remote Bag object
bag = channel.CreateChannel();
// Register this client for the callback service
bag.RegisterForCallbacks();
lblPlayerScore.Content = 0;
pWin = new PlayerLobby(this, bag.ClientCount);
pWin.Show();
this.Hide();
}
catch (Exception ex)
{
MessageBox.Show("Error Initializing Window " + ex.Message);
}
}
示例12: ClientViewModel
public ClientViewModel()
{
var channelFactory = new DuplexChannelFactory<IChattingService>(new ClientService(), "ChattingServiceEndPoint");
_server = channelFactory.CreateChannel();
This = this;
CreateCommands();
}
示例13: TestOneWayCallbackConcurencyOnNamedPipe
public void TestOneWayCallbackConcurencyOnNamedPipe()
{
var address = @"net.pipe://127.0.0.1/testpipename" + MethodBase.GetCurrentMethod().Name;
var srv = new CallbackService();
var callback = new CallbackServiceCallback();
using (var server = new ServiceHost(srv, new Uri(address)))
{
server.AddServiceEndpoint(typeof(ICallbackService), new NetNamedPipeBinding { }, address);
server.Open();
using (var channelFactory = new DuplexChannelFactory<ICallbackService>(new InstanceContext(callback), new NetNamedPipeBinding { }))
{
var client = channelFactory.CreateChannel(new EndpointAddress(address));
for (int i = 0; i < 20; i++)
client.OneWayExecute();
while (callback.Count != 20)
{
Thread.Sleep(10);
}
}
}
}
示例14: RobotClient
public RobotClient()
{
// Initilize communication channel
DuplexChannelFactory = new DuplexChannelFactory<IUiPathRemoteDuplexContract>(new InstanceContext(this), "DefaultDuplexEndpoint");
DuplexChannelFactory.Credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
Channel = DuplexChannelFactory.CreateChannel();
}
示例15: 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);
}
}