Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need to write this end point programatically in c# , this is for a chat application . //app.config part

HTML
<system.servicemodel>
       <client>
         <endpoint name="ChatEndPoint" address="net.p2p://chatMesh/ChatServer" binding="netPeerTcpBinding" bindingconfiguration="PeerTcpConfig" contract="Clinical_Vista.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>
           &lt;!--<binding name="BindingDefault" port="0">
             <security mode="None"></security>
             <resolver mode="Auto"></resolver>
           </binding>--&gt;
         </netpeertcpbinding>
         <nettcpbinding>
           <binding name="TcpConfig">
             <security mode="None"></security>
           </binding>
         </nettcpbinding>
       </bindings>
     </system.servicemodel>

// c# part

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

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

What I have tried:

C#
EndpointAddress endpointAddress = new EndpointAddress("net.p2p://chatMesh/ChatServer");
                ContractDescription contract = new ContractDescription("IChatService", "Clinical_Vista");
              
                System.ServiceModel.Channels.Binding binding = new NetPeerTcpBinding();
                binding.Name = "PeerTcpConfig";

                  ServiceEndpoint se = new ServiceEndpoint(contract, binding, endpointAddress);
                 
                InstanceContext context = new InstanceContext(
                    new Home(userName));
                factory =
                    new DuplexChannelFactory<ichatchannel>(context, se);
                channel = factory.CreateChannel();
Posted
Updated 14-Feb-16 19:44pm
v4
Comments
Sinisa Hajnal 15-Feb-16 2:59am    
Put a template in custom node, not real address. Then replace those placeholders with real values in your code .
For example {server}{port}{name} or something like that and replace those with real values.
jpvv 15-Feb-16 3:10am    
But in Code I call only the client end point only
. I need to change the binding address

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900