title: WCF, executing Events?
body: <p>While continuing to learn WCF, I'm trying to make it work with events.</p>
  
  <p>In this example, upon a button click in a form, I want my wcf service to execute and event that would be trigger something in other form that are connected to this service.</p>
  
  <p>That's the code for the Form1.</p>
  
  <pre><code>public Form1()
  {
     InitializeComponent();
     client.TimeShowEvent += new EventHandler(TimeShowEvent);
     ///// SAYS THAT IT DOES NOT CONTAIN A DEFINITION FOR TimeShowEvent
  }
  
  MyWcfService1.IfaceServiceClient client = new MyWcfService1.IfaceServiceClient();
  
  private void button2_Click(object sender, EventArgs e)
  {
     try
     {
        MyWcfService1.IfaceServiceClient client = new MyWcfService1.IfaceServiceClient();
        client.passTime();
     }
     catch
     {
        MessageBox.Show("Service not availabe!");
     }
  }
  
  void TimeShowEvent(object sender, EventArgs e)
  {
     textBox2.Text = client.timestring;
     //// SAYS THAT IT DOES NOT CONTAIN A DEFINITION FOR timestring
  }
  </code></pre>
  
  <p>and for the service:</p>
  
  <pre><code>namespace wcfLib
  {
     [ServiceContract]
     public interface IfaceService
     {
         [OperationContract]
         int wordLen(string word);
  
         [OperationContract]
         string passTime();
  
          ///// DO I NEED TO SOMEHOW DECLARE THE VARIABLES ( timestring ) AND EVENTS ( TimeShowEvent ) HERE?
     }
  }
  </code></pre>
  
  <p>Service implementation:</p>
  
  <pre><code>public class StockService : IfaceService
  {
      public event EventHandler TimeShowEvent;
  
      public string timestring = "none";
  
      public string passTime()
      {
          TimeShowEvent(this, new EventArgs());
          timestring = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
          return "";
      }
  
      public int wordLen(string word)
      {
          return word.Length;
      }
  }
  </code></pre>
  
  <p>Service host app:</p>
  
  <pre><code>public class Service
  {
      static void Main()
      {
          ServiceHost serviceHost = new ServiceHost(typeof(StockService), new Uri("http://localhost:8000/wcfLib"));
          serviceHost.AddServiceEndpoint(typeof(IfaceService), new BasicHttpBinding(), "");
          serviceHost.Open();
          Console.WriteLine("Press return to terminate the service");
          Console.ReadLine();
          serviceHost.Close();
      }
  }
  </code></pre>
  
  <p>Do I need to somehow declare events and variables in [ServiceContract]? Is so, how?...</p>
  
  <p>Thanks! :)</p>