转换为控制台应用程序后,PubSub无法发布

时间:2014-09-22 23:06:33

标签: sockets tcp connection timeout subscription

我是Pub / Sub的新手,并且在十年内没有完成TCP ...请帮忙!我有一个完美的Windows窗体Pub Sub应用程序。经过广泛的测试,我转换了" Pub"应用程序到控制台应用程序(它最终将是一个服务应用程序).​​..问题是_proxy.Publish(alertData,topicName1);在" SendEvent()"内方法因超时而失败。

以下说明:

套接字连接已中止。这可能是由于处理消息的错误或远程主机超出接收超时或基础网络资源问题引起的。本地套接字超时为' 00:00:59.9529953'。

(有一点需要注意的是,整个应用程序在到达"发布"命令之前运行不到59秒)

我已经将WinApp和控制台应用程序并排比较,并且没有看到问题...我已经搜索了谷歌和SO超过6个小时,并尝试了我能想到的一切。请帮忙!!!请指出我是否做了一些不太聪明的事情,比如错过了一些轻微的,(或主要的)哑巴,细节!谢谢

有效代码如下:

class Program
{   
    static void Main(string[] args)
    {
        PublisherClass pb = new PublisherClass();
        pb.PublisherClassStart();
    }
}

public class PublisherClass
{
    public List<String> ListOfTopics = new List<String>();
    public List<String> ButtonCreatedList = new List<String>();
    public List<RData> DataList = new List<RData>();
    private TcpListener tcpListener;
    private Thread listenThread;

    IPublishing _proxy;
    private System.Timers.Timer tmrEvent;

    /* static */
    TcpClient QFeedClientChannel = null;

    //call the entitiesmodel customer list and create all topics from the.... here...
    public void PublisherClassStart()
    {

        CreateProxy();
        _eventCounter = 0;

        QueueViaTCPListener();
        CreateTopics();

        Console.WriteLine("Press any key to Send Data to Server");
        while (true)
        {
            var Val = Console.ReadLine();
            object sender = null;
            EventArgs e = null;
            SendEvent(sender, e);
        }

        Thread.Sleep(10000); // wait for connections and topics to stabilize and then start firing the timer.
        tmrEvent = new System.Timers.Timer(100);
        tmrEvent.Elapsed += SendEvent;
        tmrEvent.Start();

    }

    static public void CreateTopics()
    {

...         }

    private void CreateProxy()
    {
        string endpointAddressInString = ConfigurationManager.AppSettings["EndpointAddress"];
        EndpointAddress endpointAddress = new EndpointAddress(endpointAddressInString);
        NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);
        _proxy = ChannelFactory<IPublishing>.CreateChannel(netTcpBinding, endpointAddress);
    }

    void SendEvent(object sender, EventArgs e)
    {
        try
        {

            lock (ListOfTopics)
            {
                lock(DataList)
                {
                    foreach (...)
                    {
                      ...
                            alertData = PrepareEvent(topicName1, topicData);
                            _proxy.Publish(alertData, topicName1);
                            _eventCounter += 1;
                            //txtEventCount.Text = _eventCounter.ToString();

                            i++;
                        }
                    }
                }
            }

        }
        catch (Exception ex )
        {
            int i = 0;
        }
        //tmrEvent.Start();            
    }

1 个答案:

答案 0 :(得分:0)

已解决:问题出在NetTCPBinding SecurityMode中。在代码审查期间,发布者更改了安全性,然后发生了需要几天时间才解决的无关紧急情况,并且服务器NetTCPBinding没有更改为匹配。观看您的安全设置!

NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);

你不应该使用&#34; none&#34;无论是!默认为传输模式......