Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF, why make it more complicated?
    primarykey
    data
    text
    <p>today i have a question regarding style of WCF communication.</p> <p>I sometimes refuse a bit so use things programmatically (want to have control myself) and I don't like huge. Sometimes communication between 2 program parts are needed, sometimes on the same machine, sometimes on network.</p> <p>So I tried to use WCF programmatically instead of using configuration files, svcutil and so on.</p> <p>If I use the following:</p> <p>a) Define a contract</p> <pre><code>[ServiceContract] public interface IMyContract { [OperationContract] bool DoSomething(string something_in); } </code></pre> <p>b) programm some code</p> <pre><code>public class MySomething: IMyContract { public bool DoSomething(string something_in) { if(String.IsNullOrEmpty(something_in) return false; return true; } } </code></pre> <p>and then programmaticly host it</p> <pre><code>Uri baseAddress = new Uri("net.tcp://localhost:48080/MySimpleService"); using (ServiceHost host = new ServiceHost(typeof(MyContract), baseAddress)) { host.AddServiceEndpoint(typeof(IMyContract), new NetTcpBinding(), ""); host.Open(); Console.WriteLine("&lt;Enter&gt; to stop the service."); Console.ReadLine(); host.Close(); </code></pre> <p>and later just consume it from another program:</p> <pre><code>var binding = new NetTcpBinding(); var endpoint = new EndpointAddress("net.tcp://localhost:48080/MySimpleService"); var channelFactory = new ChannelFactory&lt;IMyContract&gt;(binding, endpoint); IMyContract client = null; try { client = channelFactory.CreateChannel(); bool test = client.DoSomething(); ((ICommunicationObject)client).Close(); } catch (Exception ex) { if (client != null) { ((ICommunicationObject)client).Abort(); } } </code></pre> <p>what would be the drawback?</p> <p>Wouldn't it be easier to understand?</p> <p>Could such a thing cause other problems?</p> <p>(I'm mostly interested in this, because I think it is quite annoying to use svcutil and so one just because of a class change, which can simple handled manually, if the wcf service is only used for cumminication of own programs) So what am I missing?</p> <p>Is it just a bad style to do things manually instead with large unread XML files?</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.
 

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