Implementing WebSocket on Azure Server and UWP client - c#

For the development I'm doing I need real time communication between server and clients.
As far as I understand, the best way is to go WebSocket. That's ok but now I'm looking for a way to implement this kind of communication on Server (hopefully an Azure WCF Web Role, at last an Azure Asp.Net MVC, but I do prefer WCF) and on client (UWP Windows10).
I'm new on this kind of technology so I'm looking for advices in best APIs to use for both server and client, documentation and samples.
Thank you for helping out
-g

Your best friend for this is SignalR:
http://signalr.net/
This is a library that you can basically use from anywhere. It is generally used in ASP.NET projects, but not restricted to it in any form. The following thread provides you with the answer to how you can host signalR on its own:
WCF Service with SignalR

As #Pedro said, SignalR is your friend ..
In this article, you'll find an example for how to use it in Azure platform:
https://azure.microsoft.com/en-us/blog/introduction-to-websockets-on-windows-azure-web-sites/
And for the UWP, we do have support for that, this is the documentation and en example for that:
https://msdn.microsoft.com/en-us/library/windows/apps/mt186447.aspx
UPDATE:
Here's SignalR client sample for .NET, you might need it:
http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-net-client

Related

Net.Sockets, WCF or ASP.NET for a real-time chat

I want to implement my idea, develop an application that will have client/server sides and make connection of clients to server, so they will be able to transfer messages in real-time.
So i will develop using C#, but the question is : what should i use? I dont know what method will be better for that chat.
I need to choose between Net.Sockets, WCF and ASP.NET. So I ask you to help me with choise. If I use ASP.NET, I'll have to play with selfhost things, because I don't want to create a site, or something like this to use chat.
Firstly, let's start from your variants
Net.Sockets are too low level. It's hard to make acceptable protocol. But you can use existing protocol - WebSockets. There is a tutorial how to write websocket server on c#: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_server
Possibly, if you choose WCF, you can try to use WCF duplex persistent connection over netTcpBinding. It's easily to make self-hosting WCF-service. But WCF is complex and I think it's significant overhead for simple tasks. Also, as I know duplex connection works by using long polling, which wastes a lot of resources. Choose this variant carefully.
ASP.NET. If you are talking about MVC or Web Api you should use long polling, which wastes a lot of resources and isn't real realtime
There are another variant - ASP.NET SignalR (which works using WebSockets)
Here you can look how to write client: https://github.com/SignalR/SignalR/wiki/SignalR-Client
And here you can find tutorial on self-hosting of SignalR: http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host
As #nsinreal mentioned, SignalR is probably the best way to go here.
There's plenty of examples on the net - here's one that'll get you going :
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
It's for a chat application, no less :)

Send requests to desktop application server

I have the following questions:
I am creating a desktop application (Windows), and I wish the same send solitudes and interact with another application running stored in server (Windows Server), I'm programming in C #.
Is there any way? With some protocol or something related? How?
Thanks.
There's a LOT of ways to do it.
In modern way, use Server: ASP.NET WebApi and desktop application: HttpClient. This is called REST and most popular in these days.
In Windows way, use Server: WCF and desktop application: WebService. Not recommended for simple service.
Oldies but goodies way: use Socket programming.
Many folks might recommend to use REST. Try to find tutorials related on C# and Rest. There's hundreds of good articles so cannot pick one of it in this reply.

Implementing live tile push notifications in a C# asmx webservice

I have an asmx web service that hosts various data, and now I want to send live tile updates from the web service. I have understood that push notifications can be sent from cloud to WSN, but I haven't really found any good examples for custom web services. Any ideas how this can be implemented?
In addition to the great references already provided I wanted to speak specifically to the use of "custom web services." In a greenfield push notification scenario, I'd strongly recommend looking at Windows Azure Mobile Services (WAMS) which abstracts much of the underlying REST/HTTP/OAuth choreography AND provides the benefit that it's backed by the Windows Azure cloud architecture (pay for what you use, failover, data backup etc.)
Given you already have a service, you may or may not decide the benefits of WAMS are worth the code changes/migration it would require. Should you want to continue with the service you have, you will end up doing a bit of grunt work yourself - using OAuth to authenticate with WNS, etc. It's not rocket surgery, but it's tedious :) The Windows Azure Toolkit for Windows 8 did include a recipe for doing all that, but it's now deprecated by Windows Azure Mobile service.
I tackled the subject of doing the push notification flow from "scratch" leveraging ASP.NET (I used WebAPI but ASMX could be used as well) in Windows Azure Web Sites (which you might consider as a host for your service). There's a bit of ancillary work involved as you'll need somewhere to store the channel IDs for the notifications (I used the free MySQL instance) and you'll need to use OAuth to communicate to the WNS (I used a helper class posted as a Gist), but I cover all that end-to-end in a three-part blog series
Your server infrastructure (Windows vs. Linux) and the type of application (asmx vs. aspx) don't really have any impact on how you send the notifications. Notifications are sent as an HTTP POST from your server to the MPNS server with specially formatted XML data.
Here are two really good references to get you started:
Push Notification Overview
http://msdn.microsoft.com/en-us/library/windows/apps/hh913756.aspx
Sending Push Notifications
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh868244(v=win.10).aspx
Dev support, design support and more awesome goodness on the way: http://bit.ly/winappsupport
This book might be helpful. Go to Chapter 13.
http://blogs.msdn.com/b/microsoft_press/archive/2012/10/29/free-ebook-programming-windows-8-apps-with-html-css-and-javascript.aspx

Creating a chat application with Azure

What I need to do is create the server side for a chat application that will run on the iPhone, Android, Blackberry and web browsers.
To do this I am thinking of:
creating an application and hosting
it on Microsoft's Azure cloud
using XMPP as the communication
protocol.
The iPhone app that I am building will then connect to my app on the cloud and they will have very colorful conversations in TCP/IP and XMPP.
Is there a better way to do this?
Do you have any tutorials to help me start?
Not a full answer or a recommendation, but I saw a bit of the Steve Marx's presentation today which covered node.js implementation https://github.com/smarx/smarxchat at http://chat.smarx.com/
Whilst not a finished architecture, it certainly will suggest an alternative possible design!
This is an old question. But if anyone is looking for a more ready solution today, I'd recommend give Azure Communication Services a try. It offers a managed solution for chat, SMS, telephone call, and audio/video call across all platforms.
If you're writing your own xmpp server, you'll need to use a worker roles and open the necessary ports.
If you're looking to implement an existing xmpp server solution, you'll probably be better off using a VM role, building the server image and uploading it.

Simple client / server concept for .NET

I want to implement a simple cardgame in silverlight that can be played together via a server.
My question is, what concept for communication between client and server I should use.
Is it possible to use WCF to
implement the server ? I guess no because its more like a dataprovider right ?
or do I need to use .NET Remoting ? Haven't read much about it yet, but
I'm not quite sure if it is maybe out
of date ?
Maybe there are newer approaches that I don't know yet ?
Maybe someone has a good tutorial link for the beginning that is not a bad coded sample from year 2002
WCF and .NET Remoting define communication protocols, that is, they define the plumbing between client and server.
When writing a client/server application, you should use WCF as .NET Remoting is deprecated.
See this code project article and code for a simple client/server implementation using WCF. The code is for uni-directional communication, where the server responds to the client.
Here is another article, with a more complicated sample (chat client), using bi-directional communications between client(s) and server. It also uses WPF as the UI layer, so you may need to read around that if using winforms.
WCF (Windows Communication Foundation) is the .NET technology for communication. It includes simple client / server scenarios, as well as publish / subscribe and peer to peer.
Ignore .NET Remoting. It has been replaced by WCF.
I have no idea why you thought that WCF was a data provider, but you're mistaken. See the WCF Developers Center for more on WCF.

Categories