Share via

WCF - its posible - programmatically set so bindingconfiguration?

Vladimir Arkhipov 1 Reputation point
2021-05-21T03:22:09.927+00:00

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

Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Vladimir Arkhipov 1 Reputation point
    2021-05-21T08:13:34.31+00:00

    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();
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.