Note that there are some explanatory texts on larger screens.

plurals
  1. POPass to my form WCF client message
    primarykey
    data
    text
    <p>I have <code>Winforms</code> application that host <code>WCF</code> service. this is my <code>Button connect event</code>:</p> <pre><code>private void btnConnect_Click(object sender, EventArgs e) { try { // Returns a list of ipaddress configuration IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName()); // Get machine ipaddress IPAddress _ipAddress = IPAddress.Parse(tbServerIp.Text); // Create the url that is needed to specify where the service should be started urlService = "net.tcp://" + _ipAddress.ToString() + ":8000/MyService"; // Instruct the ServiceHost that the type that is used is a ServiceLibrary.service1 host = new ServiceHost(typeof(ServiceLibrary.service1)); host.Opening += new EventHandler(host_Opening); host.Opened += new EventHandler(host_Opened); host.Closing += new EventHandler(host_Closing); host.Closed += new EventHandler(host_Closed); // The binding is where we can choose what transport layer we want to use. HTTP, TCP ect. NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.TransactionFlow = false; tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; tcpBinding.Security.Mode = SecurityMode.None; // &lt;- Very crucial // Add a endpoint host.AddServiceEndpoint(typeof(ServiceLibrary.IService1), tcpBinding, urlService); // A channel to describe the service. Used with the proxy scvutil.exe tool ServiceMetadataBehavior metadataBehavior; metadataBehavior = host.Description.Behaviors.Find&lt;ServiceMetadataBehavior&gt;(); if (metadataBehavior == null) { // This is how I create the proxy object that is generated via the svcutil.exe tool metadataBehavior = new ServiceMetadataBehavior(); metadataBehavior.HttpGetUrl = new Uri("http://" + _ipAddress.ToString() + ":8001/MyService"); metadataBehavior.HttpGetEnabled = true; metadataBehavior.ToString(); host.Description.Behaviors.Add(metadataBehavior); urlMeta = metadataBehavior.HttpGetUrl.ToString(); //pbIndicator.Image = Resources.indicator_green; btnConnect.BackColor = Color.Red; btnConnect.Text = "Stop"; } host.Open(); } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } } </code></pre> <p>And this is my ServiceLibrary:</p> <pre><code>namespace ServiceLibrary { public delegate void StatusEventHandler(string srt); [ServiceContract()] public interface IService1 { [OperationContract] string MyOperation1(string myValue); [OperationContract] string MyOperation2(DataContract1 dataContractValue); [OperationContract] string HelloWorld(string str); } public class service1 : IService1 { public event StatusEventHandler StartEvent; public string MyOperation1(string myValue) { return "Hello: " + myValue; } public string MyOperation2(DataContract1 dataContractValue) { return "Hello: " + dataContractValue.FirstName; } public string HelloWorld(string str) { StartEvent(str); //return "Helloworld from " + str; } } [DataContract] public class DataContract1 { string firstName; string lastName; [DataMember] public string FirstName { get { return firstName; } set { firstName = value; } } [DataMember] public string LastName { get { return lastName; } set { lastName = value; } } } } </code></pre> <p>What i want to do is to pass the client message from <code>HelloWorld function</code> to my main form, so i try to create event inside <code>class service1</code>:</p> <pre><code>public delegate void StatusEventHandler(string srt); public event StatusEventHandler StartEvent; </code></pre> <p>but it remained null even after registered from my main form (inside my button click event) What is the simplest way to achieve that ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload