How to write C++ SignalR client to connect a C# SiganlR server - c++11

I am aware of communication between a C# server and C# client using SignalR. Along with C# client, I have C++ client apps where I need to communicate with the same C# server that is used to communicate with C# clients.
For communication between C# server(console application) and C# clients(Desktop) i followed the approach in SignalR Desktop approach
In the above link it is very clear how do we establish a connection to hub and communicate with the server. Similarly I want to have MFC application as client and I want send some messages to the MFC client from C# server. I don't have any idea like how do i establish a connection from MFC app. I don't know whether it is possible or not.
Could anyone please help with a sample on how C++ signalR client connects to a C# client.

Actually, a SignalR C++ client already exists. If you are on Windows you can use NuGet to get the package. There are different packages depending on the toolset used to build the code (important because of the runtime the client is linked against) - v120 uses toolset shipped in VS2013, v140 uses toolset from VS2015. For instance https://www.nuget.org/packages/Microsoft.AspNet.SignalR.Client.Cpp.v140.WinDesktop/1.0.0-beta2 is a package for desktop apps built with VS2015.
I wrote a post on how to use the client as well as a miniseries on using cpprestsdk (a.k.a. Casablanca) - a library which provides async functionality in C++. You need to know this stuff to be able to consume the client since it returns tasks (think promises).
The code also compiles on Linux (and I heard it can be compiled on MacOS but I personally haven't done it).

Related

Can SignalR for ASP.NET Core be self hosted in a Windows exe or a Xamarin app?

MS recently released an alpha build of SignalR for ASP.NET Core 2.0. I can't see any doco about whether it can be self hosted in a windows service, which earlier versions of SignalR supported.
Also is it possible to have self hosted in a Xamarin app? Imagine a Xamarin app that is basically a wrapper around a website. The website provides most of the functionality. However, the Xamarin app provides specialised services. The website portion would communicate with the app via websockets, which means the Xamarin form would need to be a SignalR SERVER. I ask this in the same question as the windows exe because it would be a similar model (browser <--> Windows exe vs embedded browser <--> Xamarin app). I have something like this working already (using a HttpListener with self signed certificates) but it only provides one way comms but I really need the two way comms that websockets would provide.
I could possibly get away with a more simple Web Sockets solution but would like to know if SignalR is possible. I plan to use a more traditional browser to IIS hosted SignalR solution in future for certain functions and it would be good if I could keep that consistent with the browser to local service communication I described above.

How can I create a REST API client for a Windows Runtime project in Visual Studio / by external tools?

In Visual Studio for .net projects I can use built in tools to generate API clients by swagger. It simply and works great.
This option is missing from Windows Runtime projects as well, like Windows 10 IOT ones.
What is the best way to create API clients by swagger for this? If there is no built in tool / extension for VS, any external tools are highly appriciated.
Thanks a lot!
I don't get your question completely; on Windows IOT Core you can run UWP (background) apps; they are compatible with .net framework and .net standard up to version 1.4. This should work with a generated client from swagger.
Also you can use Refit to create a REST client according to best practices based upon an interface with attribute decorations.

Is Visual Studio's Browser Link feature able to use web sockets?

I understand that SignalR is used to communicate with client browsers using the injected artery script. I have what seems to be a common problem, which is that my browser's network log is filled with entries that look like this:
.../arterySignalR/poll?transport=longPolling&connectionToken=...
This tells me that SignalR has fallen back to long polling instead of using web sockets. Assuming that we have a browser that supports web sockets, and that browser is running on the localhost, shouldn't SignalR default to using web sockets? What might cause it to fall back to long polling?
Short answer
Browser Link will only use WebSockets on Windows 8 or Windows Server 2012
Longer answer
The following would explain the issue if you're using Visual Studio on Windows 7, Windows Vista or Windows Server 2008:
IIS (Express) depends on the .NET framework implementation in System.Net.WebSockets to handle WebSocket connections; as you can read in the link to MSDN, you simply don't get an actual implementation of the necessary classes when you install .NET 4.5 on Windows 7.
So in that case, the server can't agree to the client's request to change from standard HTTP to the WebSocket protocol, which forces the SignalR client to use one of the fallback options (in your case: long-polling).

SignalR transport will not work as websocket

I have a bit of an issue.
I am using the self-hosting example (http://www.asp.net/signalr/overview/getting-started/tutorial-signalr-self-host) and I have installed the 2.0 (beta2) packages from nuget.
I have my hub running on a webserver and my js client on my localhost.
Webserver is windows server 2012 with websockets enabled in roles.
My solution is set to target .NET 4.5 BUT has started out as 4.0. I have installed the nuget packages AFTER changing the solution target.
Client is running IE9 on Win7.
Now, when I check my referenced .dll's in Visual Studio their Runtime version is listed as 4.0. I am unsure if this means anything.
My problem is, I cannot connect my JS client to the hub, IF I tell it to use websockets.
If I don't specify websockets as transport, it connects fine, through longpolling.
What do I do? I have no idea what to try next.
IE9 does not support web sockets.

XE2 FireMonkey - connect to a Web Service in iOS app

I have created an XE2 FireMonkey application which needs to run on an iPad. I am familiar with exporting to XCode and recompiling on the Mac machine. This all works quite fine.
The problem however is when I want to connect to an existing web service. Using the WSDL Import, I can create the necessary file and the functionality from my web service works as expected. This only works in a Windows environment though as the file created by the WSDL Import uses the "InvokeRegistry" which is Windows specific.
How can I connect to a web service in FireMonkey in a way which will compile on XCode and work in an iOS environment?
The Web Service Toolkit of Free Pascal is one option. According to this forum post, iOS can be used as target platform.
The toolkit includes a WSDL importer wizard, also available as command line tool ("ws_helper").
"Web Service Toolkit” is a web services package for FPC, Lazarus and
Delphi; “Web Service Toolkit” is meant to ease web services
consumption and creation by FPC, Lazarus and Delphi users.
It seems that one cannot have data connectivity in mobile iOS applications without various forms of "hacking" code. There is currently no standard way with the XE2 framework to support this.
See: http://edn.embarcadero.com/article/41729
XE5 has major improvements and data connectivity is now easily handled via DataSnap. One can easily reference existing web services via a DataSnap server, so the issues I originally had are now solved.

Resources