我需要在c#中以编程方式编写这个端点,这是一个聊天应用程序。
app.config部件
<system.serviceModel>
<client>
<endpoint name="ChatEndPoint" address="net.p2p://chatMesh/ChatServer" binding="netPeerTcpBinding" bindingConfiguration="PeerTcpConfig" contract="Test.IChatService"></endpoint>
</client>
<bindings>
<netPeerTcpBinding>
<binding name="PeerTcpConfig" port="0">
<security mode="None"></security>
<resolver mode="Custom">
<custom address="net.tcp://192.168.0.147:22222/ChatServer" binding="netTcpBinding" bindingConfiguration="TcpConfig"></custom>
</resolver>
</binding>
<!--<binding name="BindingDefault" port="0">
<security mode="None"></security>
<resolver mode="Auto"></resolver>
</binding>-->
</netPeerTcpBinding>
<netTcpBinding>
<binding name="TcpConfig">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>C#部件
InstanceContext context = new InstanceContext(
new Home(txtUserName.Text.Trim()));
factory =
new DuplexChannelFactory<IChatChannel>(context, "ChatEndPoint");
channel = factory.CreateChannel();这对我来说工作得很好。但是,我需要动态更改端点地址。寻找有价值的支持。
发布于 2016-02-15 14:31:44
使用端点选择逻辑编写您自己的ChanelFactory
https://msdn.microsoft.com/en-us/library/ms734681.aspx。
或者只需使用另一个接受EndPointAddress对象的DuplexChanelFactory构造函数,您可以在代码中使用所有必要的参数创建该对象
https://msdn.microsoft.com/ru-ru/library/ms576164(v=vs.110).aspx
https://stackoverflow.com/questions/35402661
复制相似问题