locked
Newbie question for SignalR client for XML data push service RRS feed

  • Question

  • User-742307079 posted

    Hello:

    I subscribed a sports data service.  To get the live score data (i.e. the soccer match live score), there are 2 ways: one is I write a web client and send HTTP request to their data server every minute, which I already have the code, it works.  However, this way is not good at all, for example, for one soccer match, I have to submit 90+ HTTP requests to the data server.  Usually, less than 5 of them return any non-empty data, the others are simply empty.  

    However, the sports data provider is now offering new Push data service.  I am testing it now, but I don't the code to receive their push data yet.  What they offer now is that I run an application something like a web server, which can listen on a specific URL, for example: http://mysportsdatareceiver.com/; I also set up basic authentication using simple user name/password.  Then as long as there is new live score for any soccer matches in progress, the data service provider will send to the above URL the following XML message:

    <Export xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://xmldataprovider.com/xml/xmlFeedVer1_0.xsd">
    <GeneralInformation>
    <Date>2018-06-14</Date>
    <Time>09:58:47</Time>
    <Timestamp>1561130327321</Timestamp>
    </GeneralInformation>
    <Sport code="SOC" hid="4111252" id="1" name="SOCCER">
    <Matchday date="2018-06-14">
    <Match ct="0" id="611094" leagueCode="16483" leagueSort="1" leagueType="LEAGUE" startTime="09:00"
    status="H/T" statustype="live" type="2" visible="1">
    <Home id="28530" name="Team A" standing="10" />
    <Away id="29809" name="Team B" standing="8" />
    <Information>
    <season id="151">2017/2018</season>
    <country id="1">AUSTRALIA</country>
    <parentCompetition id="0">A-LEAGUE</parentCompetition>
    <league id="2">A-LEAGUE</league>
    <shortName>D1</shortName>
    <round>20</round>
    <note />
    <bitArray>01000000100</bitArray>
    <timestamp>1261129965865</timestamp>
    </Information>
    </Match>
    </Matchday>
    </Sport>
    </Export>

    What I have done until now is: I can write a C# program using httpListener to listen on URL: http://mysportsdatareceiver.com/

    I can receive the data, but I have no idea how to settle the basic authentication issue, and receive the XML push data in real time, I need an asynchronous method to receive their real time data, so I can later on parse the XML messages and save the necessary information into SQL Server 2017 database.  I am thinking about using SignalR to write a SignalR client, which has basic authentication feature, but most importantly, it has to be able to receive XML push data in an asynchronous way, as long as the data service provider's contain the basic authentication string, like: 

    Basic uZ3poYW5nOlFHZEt5; then SignalR will recognize it as a trusted data source, and begin to receive XML message in real time.

    Please advice if this is possible or not.  (I am not sure if the data provider will be able to use WebSocket or not, but they can use HTTP 1.1 or 2.0).

    If possible, then where I can find detailed documents on this topic.  By the way, I am using Visual Studio Enterprise 2017 Version 15.7.3; C# 7.2. I can use .NET Code 2.0, .NET Core 2.1 seems not in release version, and most instructions on .NET Core 2.1 seem not correct enough to follow.  My OS is: Windows 10 Enterprise.

    I am also confused with the C# I will be writing: is it a Web Server or is it a SignalR client or both?

    Thanks,

    Friday, June 15, 2018 6:27 AM

All replies

  • User61956409 posted

    Hi zydjohn,

    You said you can receive the data from sports data provider now, if you’d like to push new live score to client in real time via ASP.NET SignalR, you can call hub method from your c# program that receives the data. 

    var hub = new Microsoft.AspNet.SignalR.Client.HubConnection("http://xxxx/signalr/hubs");
    
    var proxy = hub.CreateHubProxy("{your_hub_name}");
    hub.Start().Wait();
    
    //invoke hub method
    proxy.Invoke("{your_hub_method}", "{sports_data}");
    

    and then you can process received data in hub method and push the data to connected clients via SignalR.

    For more information about ASP.NET SignalR, you can check:

    With Regards,

    Fei Han

    Monday, June 18, 2018 7:37 AM