1

I am developing WinForm desktop application. I am successfully handshaking with CometD server and then sending change requests to the server. I am sure that requests are successfully received and request command is done by the server and finally expecting that there is a State Changed message by the CometD server. However, there is no message received to me onMessage() method. Does anyone know why? Any suggestions?

public void getCometDAuthenticationRequest(HttpWebRequest request)
    {
        request = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["MyServer"]);
        request.ContentType = "application/json; charset=utf-8";
        request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + password));
        request.PreAuthenticate = true;
        request.Method = "POST";
    }

    private void connectToCometD()
    {
        try
        {
            IClientSessionChannel channel;
            BayeuxClient client;

            Action<HttpWebRequest> customizeRequest = new Action<HttpWebRequest>(getCometDAuthenticationRequest);
            LongPollingTransport transport = new LongPollingTransport(null, customizeRequest);

            // Handshake
            string url = ConfigurationManager.AppSettings["CometDServer"];
            client = new BayeuxClient(url, new List<ClientTransport>() { transport });

            client.handshake();
            client.waitFor(1000, new List<BayeuxClient.State>() { BayeuxClient.State.CONNECTED });

            // Subscription to channels
            channel = client.getChannel("/fooChannel");
            channel.subscribe(new Listener());               

        }
        catch (Exception e)
        {
            MessageBox.Show("EXCEPTION ON connectToCometD(): " + e.Message);
            return;
        }            
    }

class Listener : IMessageListener
{
    public void onMessage(IClientSessionChannel channel, IMessage message)
    {                         
            MessageBox.Show("New Message received.. Message:" + message.ToString());             
    }       
}
cihadakt
  • 3,054
  • 11
  • 37
  • 59
  • Any update? Any luck? I have built a [very specific Java listener](https://github.com/forcedotcom/EMP-Connector) for my SalesForce site, and it handshakes and shows me change events that I initiate in my SalesForce org. But, when I build a similar app in .NET, like you, I can successfully do the handshake, but I don't receive the change events. [I started with Oyatel's CometD.NET](https://github.com/Oyatel/CometD.NET) – bkwdesign May 18 '19 at 03:59

0 Answers0