运行我的程序时关闭WCF服务

时间:2014-08-30 11:36:26

标签: c# wcf

我正在WCF在本地运行两个程序 我的第一个程序在proxy.RegisterClient();

中关闭了WCF服务
  private void Form1_Load(object sender, EventArgs e)
            {
                InstanceContext context = new InstanceContext(this);
                proxy = new Service1Client(context);
                proxy.Open();
                proxy.RegisterClient(); // Closes WCF Service

            }

我在第一个程序中的app.config

<system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="duplexendpoint" />
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:9000/Service1/" binding="wsDualHttpBinding"
                bindingConfiguration="duplexendpoint" contract="ServiceReference1.IService1"
                name="duplexendpoint">
                <identity>
                    <userPrincipalName value="ws02\khdz" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

我的第二个项目在

之后关闭WCF服务
 ClinicService.Instance.SetConnectionString(ConfigurationSettings.AppSettings["connectionstring"]);

代码是

 private void Form1_Load(object sender, EventArgs e)
        {
            InstanceContext context = new InstanceContext(this);
            proxy = new Service1Client(context);
            proxy.Open();
            proxy.RegisterClient();
            ClinicService.Instance.SetConnectionString(ConfigurationSettings.AppSettings["connectionstring"]);
        }

和app.config是

 <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="duplexendpoint" />
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:9000/Service1/" binding="wsDualHttpBinding"
                bindingConfiguration="duplexendpoint" contract="ServiceReference1.IService1"
                name="duplexendpoint">
                <identity>
                    <userPrincipalName value="ws02\khdz" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>

0 个答案:

没有答案