Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Lightstreamer创建会话_C#_.net_Lightstreamer - Fatal编程技术网

C# Lightstreamer创建会话

C# Lightstreamer创建会话,c#,.net,lightstreamer,C#,.net,Lightstreamer,我正在尝试使用LightStreamer连接到IG index streaming API,并且正在编写本教程 通过执行以下操作,我已成功创建了流式会话(第16页4.1-/lightstreamer/create_session.txt): public void ConnectToLightStreamer(Credentials credentials) { var LightStreamerRequest = (HttpWebRequest)WebRequest.Create(cr

我正在尝试使用
LightStreamer
连接到IG index streaming API,并且正在编写本教程

通过执行以下操作,我已成功创建了流式会话(第16页4.1-/lightstreamer/create_session.txt):

public void ConnectToLightStreamer(Credentials credentials)
{
    var LightStreamerRequest = (HttpWebRequest)WebRequest.Create(credentials.LIGHTSTREAMERENDPOINT + "/lightstreamer/create_session.txt");
    LightStreamerRequest.Method = "POST";
    LightStreamerRequest.ContentType = "application/x-www-form-urlencoded";
    LightStreamerRequest.Headers.Add("Cache-Control", "no-cache");

    using (var streamWriter = new StreamWriter(LightStreamerRequest.GetRequestStream()))
    {
        string Body = "LS_user=" + credentials.CLIENTID + "&LS_password=CST-" + credentials.CST + "|XST-" + credentials.SECURITY_TOKEN + "&LS_adapter_set=DEFAULT&LS_polling=true&LS_polling_millis=0&LS_idle_millis=0&LS_report_info=true";

        streamWriter.Write(Body);
        streamWriter.Flush();
        streamWriter.Close();
    }

    var httpResponse = (HttpWebResponse)LightStreamerRequest.GetResponse();
    Stream stream = httpResponse.GetResponseStream();

    using (stream)
    {
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);
        string responseString = reader.ReadToEnd();

        string[] SessionData = responseString.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

        string[] sessionID = SessionData[1].Split(':');
        credentials.SESSIONID = sessionID[1];

        string[] controlAddress = SessionData[2].Split(':');
        credentials.CONTROLADDRESS = controlAddress[1];

        Console.WriteLine(responseString);
        Console.WriteLine("CONNECTED");
        Console.WriteLine(Environment.NewLine);
        Console.WriteLine(Environment.NewLine);                
    }
}
 public void BindSession(Credentials credentials)
{
    var LightStreamerRequest = (HttpWebRequest)WebRequest.Create(credentials.LIGHTSTREAMERENDPOINT + "/lightstreamer/bind_session.txt");
    LightStreamerRequest.Method = "POST";
    LightStreamerRequest.ContentType = "application/x-www-form-urlencoded";
    LightStreamerRequest.Headers.Add("Cache-Control", "no-cache");

    using (var streamWriter = new StreamWriter(LightStreamerRequest.GetRequestStream()))
    {

        string Body = "LS_user=" + credentials.CLIENTID + "&LS_session=" + credentials.SESSIONID + "&LS_password=CST-" + credentials.CST + "|XST-" + credentials.SECURITY_TOKEN + "&LS_adapter_set=DEFAULT&LS_polling=true&LS_polling_millis=0&LS_idle_millis=0&LS_report_info=true&LS_polling_millis=1000";

        streamWriter.Write(Body);
        streamWriter.Flush();
        streamWriter.Close();
    }

    var httpResponse = (HttpWebResponse)LightStreamerRequest.GetResponse();
    Stream stream = httpResponse.GetResponseStream();

    using (stream)
    {
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);

        string responseString = reader.ReadToEnd();

        Console.WriteLine("BIND: " + responseString);
    }
}
我通过以下操作成功绑定了会话(第18/19页/lightstreamer/bind_session.txt):

public void ConnectToLightStreamer(Credentials credentials)
{
    var LightStreamerRequest = (HttpWebRequest)WebRequest.Create(credentials.LIGHTSTREAMERENDPOINT + "/lightstreamer/create_session.txt");
    LightStreamerRequest.Method = "POST";
    LightStreamerRequest.ContentType = "application/x-www-form-urlencoded";
    LightStreamerRequest.Headers.Add("Cache-Control", "no-cache");

    using (var streamWriter = new StreamWriter(LightStreamerRequest.GetRequestStream()))
    {
        string Body = "LS_user=" + credentials.CLIENTID + "&LS_password=CST-" + credentials.CST + "|XST-" + credentials.SECURITY_TOKEN + "&LS_adapter_set=DEFAULT&LS_polling=true&LS_polling_millis=0&LS_idle_millis=0&LS_report_info=true";

        streamWriter.Write(Body);
        streamWriter.Flush();
        streamWriter.Close();
    }

    var httpResponse = (HttpWebResponse)LightStreamerRequest.GetResponse();
    Stream stream = httpResponse.GetResponseStream();

    using (stream)
    {
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);
        string responseString = reader.ReadToEnd();

        string[] SessionData = responseString.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

        string[] sessionID = SessionData[1].Split(':');
        credentials.SESSIONID = sessionID[1];

        string[] controlAddress = SessionData[2].Split(':');
        credentials.CONTROLADDRESS = controlAddress[1];

        Console.WriteLine(responseString);
        Console.WriteLine("CONNECTED");
        Console.WriteLine(Environment.NewLine);
        Console.WriteLine(Environment.NewLine);                
    }
}
 public void BindSession(Credentials credentials)
{
    var LightStreamerRequest = (HttpWebRequest)WebRequest.Create(credentials.LIGHTSTREAMERENDPOINT + "/lightstreamer/bind_session.txt");
    LightStreamerRequest.Method = "POST";
    LightStreamerRequest.ContentType = "application/x-www-form-urlencoded";
    LightStreamerRequest.Headers.Add("Cache-Control", "no-cache");

    using (var streamWriter = new StreamWriter(LightStreamerRequest.GetRequestStream()))
    {

        string Body = "LS_user=" + credentials.CLIENTID + "&LS_session=" + credentials.SESSIONID + "&LS_password=CST-" + credentials.CST + "|XST-" + credentials.SECURITY_TOKEN + "&LS_adapter_set=DEFAULT&LS_polling=true&LS_polling_millis=0&LS_idle_millis=0&LS_report_info=true&LS_polling_millis=1000";

        streamWriter.Write(Body);
        streamWriter.Flush();
        streamWriter.Close();
    }

    var httpResponse = (HttpWebResponse)LightStreamerRequest.GetResponse();
    Stream stream = httpResponse.GetResponseStream();

    using (stream)
    {
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);

        string responseString = reader.ReadToEnd();

        Console.WriteLine("BIND: " + responseString);
    }
}
我的问题是创建一个会话,并确定应该发送什么信息以及如何发送。第20/21页/lightstreamer/control.txt

我有以下几点,但我知道这是错误的,因为我没有得到任何回应:

public void ControlStreamer(Credentials credentials)
{
    var LightStreamerRequest = (HttpWebRequest)WebRequest.Create(credentials.LIGHTSTREAMERENDPOINT + "/lightstreamer/control.txt");
    LightStreamerRequest.Method = "POST";
    LightStreamerRequest.ContentType = "application/x-www-form-urlencoded";
    LightStreamerRequest.Headers.Add("Cache-Control", "no-cache");

    using (var streamWriter = new StreamWriter(LightStreamerRequest.GetRequestStream()))
    {

        string Body = "LS_user=" + credentials.CLIENTID + "&LS_password=CST-" + credentials.CST + "|XST-" + credentials.SECURITY_TOKEN + "&LS_session=" + credentials.SESSIONID + "&LS_polling=true&LS_polling_millis=0&LS_idle_millis=0&LS_report_info=true&LS_polling_millis=1000&LS_table=" + credentials.SESSIONID + "&LS_op=add&LS_schema=MARKET:IX.D.DOW.DAILY.IP&LS_id=1&LS_mode=MERGE";

        streamWriter.Write(Body);
        streamWriter.Flush();
        streamWriter.Close();
    }

    var httpResponse = (HttpWebResponse)LightStreamerRequest.GetResponse();
    Stream stream = httpResponse.GetResponseStream();

    using (stream)
    {
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);

        string responseString = reader.ReadToEnd();

        Console.WriteLine("CONTROL: " + responseString);
    }
}
我已经做了大约一年的全职开发人员,这个项目正处于我的极限和理解的边缘

我已经做这个项目整整两天以上,但几乎不能理解的文件


如果有人能向我解释我做错了什么,或者给我指出一个工作示例,我将不胜感激。

如果您的应用程序基于C#,您不需要自己实现该协议,但如果您使用现成的客户端库会更好。它为您提供了更高级别的抽象,而且更健壮,并且经过了良好的测试

您可以从下载客户端库并访问完整的文档和示例

您提到的网络协议教程仅在您需要基于任何可用Lightstreamer客户端库都未涵盖的技术开发应用程序时才有用