1

I need to write this end proint programatically in c# , this is for a chat application .

app.config part

 <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# part

 InstanceContext context = new InstanceContext(
                        new Home(txtUserName.Text.Trim()));
                    factory =
                        new DuplexChannelFactory<IChatChannel>(context, "ChatEndPoint");
                    channel = factory.CreateChannel();

This is working fine for me. However, I need to change the end point address dynamically. Looking for valuable support.

1 Answers1

0

Wright your own ChanelFactory with endpoint selection logic

https://msdn.microsoft.com/en-us/library/ms734681.aspx.

Or just use another constructor of DuplexChanelFactory that takes EndPointAddress object which you can create at code with all necessary parameters

https://msdn.microsoft.com/ru-ru/library/ms576164(v=vs.110).aspx

Ivan
  • 312
  • 1
  • 4
  • 14
  • I tried but here i need to use DuplexChannelFactory . When I configure it , it have some parameters like ServiceEndpoint or binding and remote address – user2972244 Feb 15 '16 at 10:06
  • Can you check the above configuration , Do you have any solution – user2972244 Feb 15 '16 at 10:11
  • @user2972244 DuplexChannelFactory has many constructors: https://msdn.microsoft.com/ru-ru/library/ms576164(v=vs.110).aspx. You use one that takes endPoint name at configuration file. Instead of doing this, you have to make EndPointAddress object manually with needed ip and path it to another constructor. Then you can wright any logic you want to find out ip or other endPointAddress settings – Ivan Feb 15 '16 at 10:33
  • here I have one end point with p2p, That I can write. But Acual working is based on the tcp bing. How can I include That binding – user2972244 Feb 15 '16 at 12:59
  • @user2972244 you can load it from configuration file, or make it programmatically. In my project we hardcoded behaviour and bindings, because 98% time nobody change it in configuration. It's only installation dificulties – Ivan Feb 15 '16 at 13:53
  • @Ivan - can you show how it make programmatically? – Архипов Владимир May 20 '21 at 05:09