首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以编程方式编写端点(netPeerTcpBinding)

如何以编程方式编写端点(netPeerTcpBinding)
EN

Stack Overflow用户
提问于 2016-02-15 14:16:36
回答 1查看 444关注 0票数 1

我需要在c#中以编程方式编写这个端点,这是一个聊天应用程序。

app.config部件

代码语言:javascript
复制
 <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#部件

代码语言:javascript
复制
 InstanceContext context = new InstanceContext(
                        new Home(txtUserName.Text.Trim()));
                    factory =
                        new DuplexChannelFactory<IChatChannel>(context, "ChatEndPoint");
                    channel = factory.CreateChannel();

这对我来说工作得很好。但是,我需要动态更改端点地址。寻找有价值的支持。

EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35402661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档