0

I understand the basics behind the Javascript examples, but I'm having difficulty seeing how this will work with WCF. My goal is to enable COMET (HTTP Push) style access to my data, but I'm not sure if Rx is the right technology.

How do I use Javascript Rx Extensions with WCF?

Community
  • 1
  • 1
makerofthings7
  • 60,103
  • 53
  • 215
  • 448

1 Answers1

1

Does WCF support HTTP Push? It's fairly easy to convert an arbitrary callback into an Rx Observable, here's how I did it (in Coffeescript):

this.createRxCallback = () ->
  subj = new Rx.Subject()
  subj.callback = (params...) -> subj.OnNext(params)
  return subj

Then you can take any function that requires a callback, like this example from Socket.io:

socket = new io.Socket {node_server_url}
socket.connect()

myCoolObservable = createRxCallback()
socket.on 'message', myCoolObservable.callback

myCoolObservable.Subscribe (x) ->
  console.log x

Or a simple example:

clickObservable = createRxCallback()
document.addEventListener 'myButton', clickObservable.callback, true

clickObservable.Subscribe (x) ->
  console.log "Button was clicked!"
Ana Betts
  • 73,868
  • 16
  • 141
  • 209
  • I've never used coffescript before; Is that something I should learn instead of getting deeper with Javascript? I'm mostly a C# guy – makerofthings7 Apr 06 '11 at 16:45
  • Since I'm using Azure, the backend node the TCP Socket is bound to may be restarted. How should I handle that error? – makerofthings7 Apr 06 '11 at 16:47
  • @makerofthings7 Coffeescript is a "dialect" of Javascript - it's definitely worth learning though I don't know how much support exists for ASP.NET (i.e. to translate coffee -> js on the fly) - it makes using RxJS much cleaner because of RxJS's heavy dependence on lambda expressions. – Ana Betts Apr 06 '11 at 20:14
  • This is still confusing to me... can someone post a javascript sample? From what I can tell XMLHttpRequest is the closest to sockets we can get... – makerofthings7 Apr 06 '11 at 22:23
  • This code won't work anymore subj.OnNext(params) needs to be subj.onNext(params) – Christoph Hegemann Dec 21 '14 at 18:00