question

VladimirArkhipov-9024 avatar image
0 Votes"
VladimirArkhipov-9024 asked VladimirArkhipov-9024 answered

WCF - its posible - programmatically set so bindingconfiguration?

in client app.config:

 <system.serviceModel>
     <client>
       <endpoint name="FileEndPoint" address="net.p2p://ChangingName123/FileServer"
                 binding="netPeerTcpBinding" bindingConfiguration="PeerTcpConfig"
                 contract="FileClient.IFileService"></endpoint>
         
          
    </client>
    
     <bindings>
       <netPeerTcpBinding>
         <binding name="PeerTcpConfig" port="0">
           <security mode="None"></security>
           <resolver mode="Custom">
             <custom address="net.tcp://191.14.3.11/FileServer" binding="netTcpBinding"
                     bindingConfiguration="TcpConfig"></custom>
           </resolver>
         </binding>
            
       </netPeerTcpBinding>
       <netTcpBinding>
         <binding name="TcpConfig">
           <security mode="None"></security>
         </binding>
       </netTcpBinding>
     </bindings>
   </system.serviceModel>

client code:

 InstanceContext context = new InstanceContext(
                         new ChatClient(numberclient);
 DuplexChannelFactory<IFileChannel> factory =
                         new DuplexChannelFactory<IFileChannel>(context, "FileEndPoint");
 IFileChannel channel = factory.CreateChannel();
                                            
 channel.Open();


need all setings put in code client. I begine make so:

 NetPeerTcpBinding binding = new NetPeerTcpBinding();
                
 EndpointAddress endpoint = new EndpointAddress("net.p2p://ChangingName123/FileServer");
    
 InstanceContext context = new InstanceContext(
                         new ChatClient(numberclient);
 DuplexChannelFactory<IFileChannel> factory =
                         new DuplexChannelFactory<IFileChannel>(context, binding, endpoint);

but "PeerTcpConfig" have custom address="net.tcp://191.14.3.11/FileServer" and have bindingConfiguration="TcpConfig"

how I can set for binding custom address in code and set one more binding TcpConfig for NetPeerTcpBinding binding





dotnet-csharpwindows-wcf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

VladimirArkhipov-9024 avatar image
0 Votes"
VladimirArkhipov-9024 answered

finded solution:

 InstanceContext context = new InstanceContext(new ChatClient(numberclient));
 NetPeerTcpBinding binding = new NetPeerTcpBinding();
    
 EndpointAddress endpoint = new EndpointAddress("net.p2p://ChangingName123/FileServer");
 binding.Resolver.Custom.Address = new EndpointAddress("net.tcp://191.14.3.11/FileServer");
 binding.Security.Mode = SecurityMode.None;
 NetTcpBinding ntcp = new NetTcpBinding();
 ntcp.Security.Mode = SecurityMode.None;
 binding.Resolver.Custom.Binding = ntcp;
 factory = new DuplexChannelFactory<IChatChannel>(context, binding, endpoint);
 channel = factory.CreateChannel();


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.