从客户端停止自托管服务器

时间:2014-04-10 05:43:01

标签: c# wpf wcf

我刚刚开始学习WCF。目前我正在开发一个项目,我在控制台应用程序上“自托管”服务器,客户端是WPF应用程序。

合同

 [ServiceContract]
public interface IDemoValue
{
    [OperationContract]
    double IncrementByHundred(double val);
}

服务器

class Program
{
    static void Main(string[] args)
    {
        using(ServiceHost host=new ServiceHost(typeof(WcfServiceDemos.DemoValue)))
        {
            host.Open();

            Console.WriteLine("Host is running at {0}", DateTime.Now.ToString());

            Thread.Sleep(2000);
        }
    }
}

</pre></code>

As from the code is clear that i am trying to Host WcfSericesDemos.DemoValue class.

CLIENT

//Event to start server (on button click) private void Button_Click(object sender, RoutedEventArgs e) { object val1 = regKey.GetValue("SERVER"); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = true; startInfo.FileName = val1.ToString();

try { using (Process proc = Process.Start(startInfo)) { double inputValue = Convert.ToDouble(Input.Text); //Here IncrementByHundred(inputValue) is a method from DemoValue which iam trying to expose through WCF OutPut.Content = server.IncrementByHundred(inputValue); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }

现在我的问题是在IncrementByHundred()方法被调用之前服务器正在关闭。 所以底线,我想在IncrementByHundred()完成任务后从客户端停止服务器。

仅供参考:我已经尝试在服务器上运行Console.Readline(),服务器上的工作仍在运行,但是我想在IncrementByHundred()方法完成后关闭服务器工作

提前致谢

0 个答案:

没有答案
相关问题