locked
SignalR Service hosting and calling it through Web as well as Xamarin Form RRS feed

  • Question

  • User647530521 posted

    Hi,

    Can someone please help me with following : 

    1. Create Signal R Service host it on IIS server
    2. Call that service and pass messages/chats from asp.net
    3. Call same service on Xamarin Mobile App

    Thanks in advance

    Thursday, August 30, 2018 12:17 PM

All replies

  • User283571144 posted

    Hi a.khanna,

    • Create Signal R Service host it on IIS server
    • Call that service and pass messages/chats from asp.net

    According to your description, I suggest you could refer to below article to know how to create the SignalR hub class in the server-side and how to call the SignalR hub in client-side.

    ASP.NET SignalR Hubs API Guide - Server (C#)

    ASP.NET SignalR Hubs API Guide - JavaScript Client

    ASP.NET SignalR Hubs API Guide - .NET Client (C#) 

    Call same service on Xamarin Mobile App

    About how to call the SignalR in  Xamarin Mobile App, I suggest you could refer to below article.

    https://medium.com/@edgarleonardo/websockets-implementation-with-signalr-and-xamarin-forms-d9244fa128da 

    Best Regards,

    Brando

    Friday, August 31, 2018 3:20 AM
  • User647530521 posted

    Thanks.

    I have hosted my services on server and have a URL. Now when i am opening that URL and posting something it is working.

    I want to call that URL on my local machine code so that it syncs with that. What ever I post there should appear on my localhost & vice versa.

    How to append that URL in local application i.e how should i map "app.MapSignalR();"

    Regards

    Tuesday, September 4, 2018 7:05 AM
  • User283571144 posted

    Hi a.khanna,

    Do you mean you want to know how to call the signlar url in the Xamarin Form?

    As far as I know, we could directly use  Microsoft.AspNet.SignalR.Client in the  Xamarin Form.

    You should firstly find the signlar url as below article shows:

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#signalrurl 

    Codes as below:

    var hubConnection = new HubConnection("http://www.contoso.com/");
    IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("StockTickerHub");
    stockTickerHubProxy.On<Stock>("UpdateStockPrice", stock => Console.WriteLine("Stock update for {0} new price {1}", stock.Symbol, stock.Price));
    await hubConnection.Start();

    Best Regards,

    Brando

    Wednesday, September 5, 2018 7:03 AM
  • User647530521 posted

    Not Xamarin. Xamarin we have figured out how to call a SignalR Service hosted at Azure.

    Challenge I am facing is calling that Azure Hosted URL (http://xxx.azurewebsites.net/) from my asp.net form. I m getting following error in console :

    jQuery-3.2.1.min.js:4 GET http://xxx.azurewebsites.net/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&_=1536136991094 404 (Not Found)
    Chat.aspx:1 Failed to load http://xxx.azurewebsites.net/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&_=1536136991094: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:52106' is therefore not allowed access. The response had HTTP status code 404.

    Wednesday, September 5, 2018 8:48 AM
  • User283571144 posted

    Hi a.khanna,

    Not Xamarin. Xamarin we have figured out how to call a SignalR Service hosted at Azure.

    Challenge I am facing is calling that Azure Hosted URL (http://xxx.azurewebsites.net/) from my asp.net form. I m getting following error in console:

    jQuery-3.2.1.min.js:4 GET http://xxx.azurewebsites.net/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&_=1536136991094 404 (Not Found)
    Chat.aspx:1 Failed to load http://xxx.azurewebsites.net/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&_=1536136991094: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:52106' is therefore not allowed access. The response had HTTP status code 404.

    According to your error message, I guess the issue is related with the CORS issue.

    I suggest you could try to enable the cors in the hub application, then it will work well.

    More details about how to enable the cors, you could refer to below issue.

    https://github.com/aspnet/SignalR/issues/1400 

    Best Regards,

    Brando

    Thursday, September 6, 2018 9:20 AM