today i have a question regarding style of WCF communication.
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.
So I tried to use WCF programmatically instead of using configuration files, svcutil and so on.
If I use the following:
a) Define a contract
[ServiceContract]
public interface IMyContract
{
[OperationContract]
bool DoSomething(string something_in);
}
b) programm some code
public class MySomething: IMyContract
{
public bool DoSomething(string something_in)
{
if(String.IsNullOrEmpty(something_in)
return false;
return true;
}
}
and then programmaticly host it
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("<Enter> to stop the service.");
Console.ReadLine();
host.Close();
and later just consume it from another program:
var binding = new NetTcpBinding();
var endpoint = new EndpointAddress("net.tcp://localhost:48080/MySimpleService");
var channelFactory = new ChannelFactory<IMyContract>(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();
}
}
what would be the drawback?
Wouldn't it be easier to understand?
Could such a thing cause other problems?
(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?
Is it just a bad style to do things manually instead with large unread XML files?