简体   繁体   中英

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.

  1. 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.

  2. 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).

  3. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM