【问题标题】:PubSub fails publication after converting to console app转换为控制台应用程序后,PubSub 发布失败
【发布时间】:2014-11-17 00:41:24
【问题描述】:

我是 Pub/Sub 的新手,十年没做过 TCP...请帮忙!我有一个运行良好的 Windows 窗体 Pub Sub 应用程序。经过广泛的测试,我将“Pub”应用程序转换为控制台应用程序(最终将成为服务应用程序).​​.....问题是 _proxy.Publish(alertData, topicName1);由于超时,“SendEvent()”方法内部失败。

例外情况如下:

套接字连接被中止。这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题造成的。本地套接字超时为 '00:00:59.9529953'。

(注意一点,整个应用程序在到达“发布”命令之前运行了不到 59 秒)

我已经并排比较了 WinApp 和 Console App 并没有发现问题...我已经搜索了 google 和 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();            
    }

【问题讨论】:

  • 仅供参考:代码的失败行接近最底部...并且异常中的整数只是调试代码以设置断点...

标签: sockets tcp connection timeout subscription


【解决方案1】:

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

NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);

你也不应该使用“none”!默认是传输模式...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多