【问题标题】:WCF host in Windows service, change url dynamicallyWindows服务中的WCF主机,动态更改url
【发布时间】:2010-11-17 09:02:17
【问题描述】:

我想通过 windows 服务托管 wcf 服务。在客户端应用程序中,我想提供功能,让客户端可以选择他想要使用的 wcf 服务。

情景,

  1. 在 MacA 上的 Windows 服务中托管 WCF
  2. 在 MacB 上的 windows 服务中托管 WCF,这两个服务是相同的。
  3. 现在客户端可以选择 MacA 服务或 MacB 服务。

谢谢, Mrinal Jaiswal

【问题讨论】:

    标签: windows wcf service hosting


    【解决方案1】:

    首先你必须将 WCF url 放在客户端的 app.config 中,然后在登录表单上你可以要求用户指定服务的 IP 和端口。

    这是我的一个项目中的一段代码:

    private void btnLogin_Click(object sender, EventArgs e)
    {
                string url = "net.tcp://" + txtServer.Text + ":" + txtPort.Text + "/NoxService/";
                Program.Config.AppSettings.Settings["ServerAddress"].Value = url;
                Program.Config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
                //set server ip
                Program.NoxProxy.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ServerAddress"]);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-05
      • 2018-12-15
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多