WCF without IIS Service Not Starting for TCP on Intranet

149 views Asked by At

I am trying to create a WCF service in a WinForm with multiple console client applications. The example is to display all messages from the console applications on a tabbed winForm. I do not wish to use IIS and I am currently using NetTcpBinding as the solution will only be run on local networks.

I have created a WCF Service Library

[ServiceContract]
[ServiceKnownType(typeof(UpdateResponse))]
[ServiceKnownType(typeof(RegisterResponse))]
public interface IFirstService
{
    [OperationContract]
    Dictionary<String, MyType> GetRecords();

    [OperationContract]
    RegisterResponse Register(string keyName, bool boolValue);

    [OperationContract]
    UpdateResponse Update(string keyName, string update);
}

[DataContract]
public class MyType
{
    private bool _boolValue = true;
    private List<String> _stringList = new List<string>();

    [DataMember]
    public bool BoolValue
    {
        get { return _boolValue; }
        set { _boolValue = value; }
    }

    [DataMember]
    public List<string> StringList
    {
        get { return _stringList; }
        set { _stringList = value; }
    }
}

[DataContract]
public enum UpdateResponse
{
    [EnumMember]
    Success = 0,

    [EnumMember]
    NotRegistered = 1
}

[DataContract]
public enum RegisterResponse
{
    [EnumMember]
    Success = 0,

    [EnumMember]
    Failed = 1
}

And also a WinForm application that starts the service

private void Form1_Load(object sender, EventArgs e)
    {
        _myServiceHost = new ServiceHost(typeof (FirstService));
        _myServiceHost.AddServiceEndpoint(
                 typeof (IFirstService), 
                 new NetTcpBinding(), 
                 new Uri("net.tcp://localhost:9929/FirstService"));
        _myServiceHost.Open();

        _firstService = new FirstService();
    }

When I run the application a message is displayed saying WcfSvcHost has been hosted but more detail shows the Service has been Stopped as no end points have been defined.

I setup my client by creating an object to the service like

var address = new EndpointAddress(new Uri("net.tcp://localhost:9929/FirstService"));
var binding = new NetTcpBinding();
var factory = new ChannelFactory<IFirstService>(binding, address);
var firstService = factory.CreateChannel();

Any advice as to why the service is not starting would be great! Thank you

0

There are 0 answers