Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would not have the service class that implements the service contract (interface) be the form - make it a separate interface, a separate class. The reasoning behind this is the fact that the service host will have to create (instantiate) one instance of the service class for each request it needs to handle --> make those classes as small as possible and don't bloat them by baggage (like the Winform) that they don't need for their job!</p> <p>Then instantiate a ServiceHost inside your Winform - but make that a global member variable of the form! Otherwise, the ServiceHost is gone once your ButtonClick event is finished!</p> <pre><code>// Define a service contract. [ServiceContract(Namespace = "http://WindowsFormsApplication11")] public interface IWmsStat { [OperationContract] string sayHello(string name); } public class YourServiceClass : IWmsStat { public string sayHello(string name) { return "hello there " + name + " nice to meet you!"; } } public partial class Form1 : Form { private ServiceHost _host = null; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Create a ServiceHost for the CalculatorService type and // provide the base address. _host = new ServiceHost(typeof(YourServiceClass)); // Open the ServiceHostBase to create listeners and start // listening for messages. _host.Open(); } </code></pre> <p>Don't mix the class that contains the ServiceHost, with the ServiceClass (which will need to be instantiated by the host to satisfy incoming requests) - the Service implementation should be standalone, and as lean as possible!</p> <p>Also, it's good practice to follow the Single Responsability Principle - one class should have one job and one job only - don't pack up your whole app logic into a single, huge class - separate out the different jobs into separate classes and compose those together.</p> <p>Marc</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