Best approach for Java web service sending data to C# client - c#

Here’s our architecture:
JIRA webhook sends messages to a Java Jersey REST service when issues are assigned.
C# client application registers the username/host machine combo with the Java web service when a user logs into the machine
When the web service receives a message from JIRA, it finds the assignee username and sends the required data to the C# client app on the host machine(s) the user is logged into.
I’ve thought of a couple approaches to solve the web service to client message.
My first is opening a TCP port on the client and having the service send each message directly to it. This is the most straight-forward approach but makes the client a little heavy in that it maintains the list of user assigned ticket data that they can then manipulate (acknowledge or remove).
The other is having the service maintain the data model and the client requests data periodically. This makes the client simpler but then I’d have to implement a polling interval to grab data, and add some POST methods for acknowledging and removing data from the user’s list.
I was looking into different ways to have the client register a channel with the service, like ServiceStackEvents, but I can’t see a way to make that work with a C# client and Java service. Something like that would be perfect. A way for the service to send callbacks or event messages to a client based on a user filter.
If someone has some suggestions or knows of an API to help with this, please post a link so I can dig into it. The POSTs are all working swimmingly, it’s just getting the data back to the clients that I’m struggling with the best approach.
Thanks!

Client polling is not a terrible solution.
But if you want a firewall and proxy friendly duplex protocol, check out WebSockets https://en.m.wikipedia.org/wiki/WebSocket.

Related

C# Singalr to receive data from backand servers

I have a chat SignalR server, the chat support group chatting.
I also have a server which actually creates the groups and other group managment tools.
Whenever a user leaves a group (via http post ) to server, I want the chat service to trigger some methods, such as LeaveGroup and some other logictics.
I bound the connectionId to userId so I got the parsing request covered.
QUESTION IS: What is the best practice of communication between server/service and the signalr server.
Taking in mind, I dont want to compormise on scalability on each of my servers/services.
My idea is more or less host a web api server inside the SignalR server, but I can't seem to find any topics suggesting that could damage the performance.
Ideas?
Thanks alot.
p.s
I know that there is no code involved in here. but it seems irrelevant. I have self hosted web api in a window service I have, so the code is pretty much the same.
I would love to provide more data/information if thats neccesary
It seems like this documentation is most applicable to what you're trying to do: https://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-signalr
It speaks specifically about how to communicate from your server/service application to the signalr clients. Communicating from the client to the server/service could be done either through the signalr hub, or with other web API.
From a best practice perspective, the documentation specifically states (https://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server#callfromoutsidehub):
If you need to use the context multiple-times in a long-lived object,
get the reference once and save it rather than getting it again each
time. Getting the context once ensures that SignalR sends messages to
clients in the same sequence in which your Hub methods make client
method invocations. For a tutorial that shows how to use the SignalR
context for a Hub, see Server Broadcast with ASP.NET SignalR.
If you're really into scalability, you might want to look into integrating your signalr communications into some other message queueing system, but that's probably overkill for most circumstances.

Messaging between WCF REST service and Windows Phone app

I would like to implement some instant messenger-like application for Windows Phone 8.1, and I have a WCF REST service which connects to a MySQL database (I know, SQL Server would be better, but renting a server for MySQL is cheaper... :D), which stores users, etc.
I know that REST is stateless, but I would like to implement something session-like methodology to make my web service able to deliver incoming messages through the service to the recipients immediately (sending messages/request to the web service is not a problem).
So my question is, what technology / solution would you recommend for me to do this?
My basic concept is:
user registers from WP - service saves data to db
user logs in from WP - I will need some session like data, to let the server know where should it deliver messages (for example user's guid, ip address or something else, something that signals that the user is still online though the application is suspended and runs in background, and still able to receive messages)
user sends a message from WP to the rest service which should contain data about the sender (at least the user's guid, but don't wanna store too much data about user on the client side), the recipient, the content, timestamp, etc) via sending a http request for example using an uri template like this: message/send and in the request body there is the recipient's id, content, etc
user adds a contact
WCF service receives the request, processes it, sends to the recipient by identifying via it's guid and there comes the problem, should know something about the device, an ip address or session or something like that
recipient receives the message.
I hope I could describe my problem properly, and there will be anyone who can help me ^^
I would appreciate any helps!
Thanks in advance!
There’re several approaches that will work.
Use Microsoft’s push notification service (MPNS). Here’s an overview. This is the most power-efficient way, and your users will even be able to receive messages while your app’s not running.
Use Microsoft’s Windows Notification Service (WNS). It's only supported on WP 8.1, but the latency is much better (AFAIR they promise delivery time within 5 seconds).
Or, you can use some bi-directional protocol. Choose between:
WCF server + net-tcp transport: on client you'll have to implement binding + framing + SOAP yourself, the higher levels of the protocol (binary XML serialization) is in the framework.
Google protocol buffers over TCP
WebSockets: MS has the support in 8.1 SDK, third party is available for WP Silverlight
SignalR: 3rd party implementation is available

Communication between ASP MVC and WinForm Applications

I am looking for a way user can communicate between an ASP and Winform applications.
I am looking for something like soluto.com, I want to let the user send commands to other computers via Website. So let's say the user signed up for 10 computers, which is registered on the mvc app. User can select all the 10 computer and send a "Do this task" with a click of a button.
I am thinking something like, Winform will create a httplisten server. Everytime winform is open, it will send a "I am online" post to mvc, along with IP:Port. The server will send a request to that ip:port when required.
That approach seems very unsecure though, having an open port, configuring firewall and etc, seems like a overkill.
I was wondering if there way any other way of accomplishing this.
Thank you for the help.
P.S. Before you claim this is a stupid idea, Piriform is doing something like this also. Take a look at Agomo.com
Use SingalR with properly architected web and windows applications (e.g. MVP, MVC, etc.)
SignalR with window client (WPF)
Console App & SignalR
Create a WCF service within the WinForm application, specify endpoint(s) (and secure the endpoint appropriately), and connect to said endpoints from your ASP.NET application the same way you would also connect to a WCF service.
Why don't you just have the Winforms app use a standard HttpClient or WebRequest to periodically poll the service (maybe every 5 seconds or so) and ask if there if there are any tasks that need to be performed?
Unless you need realtime, low-latency, high performance communication then this is the easiest way to solve your problem with minimal to zero client side setup or security configuration.
The way I would do it is implement it like a stack in a data persistence layer. So each client could have rows in a table that are added when a task is queued. When the clients sends an HTTP GET request to the MVC server it will return the an array of tasks for that client and you could have it either delete them from the database right away or wait for the client to send a HTTP command later to indicate which tasks it completed.
You could represent tasks as a simple data object with a few properties, or just a string or int that you can lookup on the client in some way to invoke the appropriate code.
For reasonable security each client just needs to be given a unique key like a GUID or equivalent that it can later send to the server to validate its identity. This is also known as a cookie, secret, or API key.

is it possible to make an Asp.net IRC client?

I want to build a web-based irc client with JQuery. I know I need to open a socket to the irc server. What I'm wondering is, is it possible to open a socket purely from server-side C# code? Or would the nature of a web application prevent this and I would have to write a service to run on the host machine?
Thanks for any help :)
Yes, you should be able to make a socket connection from server-side ASP.NET code. On the other hand, given that you'd presumably want a persistent connection to the IRC server (rather than a new one on every request), you may want to write a separate service anyway - you don't want ASP.NET recycling to kick in and wipe all your context, for example.
Your ASP.NET code could then talk to your service to find out what had happened since the last request for that user, etc.
One simple approach would be to setup a singleton WCF service which acts as the bridge to IRC. jQuery AJAX calls against that service could then post messages that were input by the user, as well as retrieve messages sent by other users.
I have implement the chat with ASP.Net by using the SingnalR for duplex communication.
What I really done consist on the following steps.
1) ChatHub.cs
I have write down all the logic to connect with the IRC server and connect to the channels, receive different messages and notification from the IRC server. I then send these notifications to my ChatHub client by calling the javascript call backs from the ChatHub.cs
2) Client.aspx
Simple HTML page and it is using jquery to register the callbacks from the ChatHub.cs
3) IRCDotNet.dll
I have used this library to communicate with the IRC Server.
Hope, It will help somebody. Here is the link to download the IRCDotNet.dll
http://ircdotnet.codeplex.com/releases/view/50639

WCF duplex communication

I need to re-write an existing client-server application.
The existing application communicate using socket, I have to convert it into WCF.
At server side I need to
Monitor connected clients
Validate client request
Broadcast live data (comming from diff source).
Listen to client and respond to it
At client end I need to
Receive server broadcast and display it on UI.
Display UI and take input from user
Submit user data to server and display response
I have chosen tcp protocol on self hosting environment.
I need some immediate level references (link, tutorial, book)...
Have a look at this MSDN article, covers pretty much everything you need to know to build a duplex service in WCF:
http://msdn.microsoft.com/en-us/magazine/cc163537.aspx
You can try this : WCF on MSDN
I don't know if you can get it, but Microsoft book on WCF (course 6461A) is not bad.

Categories

Resources