Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Streaming live results to a web site using MSMQ/Duplex WCF/SignalR/jQuery

, , 7 Feb 2012
Streaming live results to a web site using MSMQ/Duplex WCF/SignalR/jQuery
Prize winner in Competition "Best Web Dev article of February 2012"
Codeproject.EventBroker.zip
Codeproject.EventBroker
Codeproject.EventBroker.Common
Properties
Codeproject.EventBroker.Contracts
Codeproject.Omni.EventBroker.Contracts.csproj.vspscc
Data
Faults
Properties
Service
Codeproject.EventBroker.Host
Codeproject.EventBroker.Host.csproj.user
Codeproject.Omni.EventBroker.Host.csproj.vspscc
Properties
Codeproject.EventBroker.Service
Codeproject.Omni.EventBroker.Service.csproj.vspscc
Data
Extensions
IOC
Properties
Services
Contracts
Implementation
Codeproject.EventBroker.suo
Codeproject.EventBroker.TestMessagePublisher
Codeproject.EventBroker.TestMessagePublisher.csproj.user
Codeproject.EventBroker.TestMessagePublisher.csproj.vspscc
Properties
queue.png
Codeproject.EventBroker.WebUI
App_Data
Codeproject.EventBroker.WebUI.csproj.user
Codeproject.EventBroker.WebUI.csproj.vspscc
Content
Images
person.png
GeoLocation
Global.asax
Properties
Scripts
Styles
Wcf
Lib
Apache
log4net
1.2.10.0
log4net.dll
Castle
1.2.0.6623
Castle.Components.Binder.dll
Castle.Components.Validator.dll
Castle.Core.dll
Castle.DynamicProxy2.dll
Castle.MicroKernel.dll
Castle.Windsor.dll
Microsoft
SignalR
SignalR.dll
(function(n,t){"use strict";if(typeof n!="function")throw"SignalR: jQuery not found. Please ensure jQuery is referenced before the SignalR.js file.";if(!t.JSON)throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8.";var i,r;i=function(n){return new i.fn.init(n)},i.fn=i.prototype={init:function(n){this.url=n},start:function(r,u){var f=this,e={transport:"auto"},o;return f.transport?f:(n.type(r)==="function"?u=r:n.type(r)==="object"&&(n.extend(e,r),n.type(e.callback)==="function"&&(u=e.callback)),n.type(u)==="function"&&n(f).bind("onStart",function(){u.call(f)}),o=function(t,r){r=r||0;if(r>=t.length){if(!f.transport)throw"SignalR: No transport could be initialized successfully. Try specifying a different transport or none at all for auto initialization.";return}var u=t[r],e=n.type(u)==="object"?u:i.transports[u];e.start(f,function(){f.transport=e,n(f).trigger("onStart")},function(){o(t,r+1)})},t.setTimeout(function(){n.post(f.url+"/negotiate",{},function(t){f.appRelativeUrl=t.Url,f.clientId=t.ClientId,n(f).trigger("onStarting");var u=[],r=[];n.each(i.transports,function(n){r.push(n)}),n.isArray(e.transport)?n.each(e.transport,function(){var t=this;n.type(t)!=="object"&&(n.type(t)!=="string"||n.inArray(""+t,r)<0)||u.push(n.type(t)==="string"?""+t:t)}):n.type(e.transport)!=="object"&&n.inArray(e.transport,r)<0?u=r:u.push(e.transport),o(u)})},0),f)},starting:function(t){var i=this;return n(i).bind("onStarting",function(){t.call(i)}),i},send:function(n){var t=this;if(!t.transport)throw"SignalR: Connection must be started before data can be sent. Call .start() before .send()";return t.transport.send(t,n),t},sending:function(t){var i=this;return n(i).bind("onSending",function(){t.call(i)}),i},received:function(t){var i=this;return n(i).bind("onReceived",function(n,r){t.call(i,r)}),i},error:function(t){var i=this;return n(i).bind("onError",function(){t.call(i)}),i},stop:function(){var n=this;return n.transport&&(n.transport.stop(n),n.transport=null),n}},i.fn.init.prototype=i.fn,i.transports={webSockets:{send:function(n,t){n.socket.send(t)},start:function(i,r,u){var f,o=!1,e;t.MozWebSocket&&(t.WebSocket=t.MozWebSocket);if(!t.WebSocket){u();return}i.socket||(f=document.location.host+i.appRelativeUrl,n(i).trigger("onSending"),f+=i.data?"?connectionData="+i.data+"&transport=webSockets&clientId="+i.clientId:"?transport=webSockets&clientId="+i.clientId,e=document.location.protocol==="https:"?"wss://":"ws://",i.socket=new t.WebSocket(e+f),i.socket.onopen=function(){o=!0,r&&r()},i.socket.onclose=function(t){o?typeof t.wasClean!="undefined"&&t.wasClean===!1&&n(i).trigger("onError"):u&&u(),i.socket=null},i.socket.onmessage=function(r){var u=t.JSON.parse(r.data);u&&(u.Messages?n.each(u.Messages,function(){n(i).trigger("onReceived",[this])}):n(i).trigger("onReceived",[u]))})},stop:function(n){n.socket!==null&&(n.socket.close(),n.socket=null)}},longPolling:{start:function(i,r){i.pollXhr&&i.stop(),i.messageId=null,t.setTimeout(function(){(function u(i){n(i).trigger("onSending");var r=i.messageId,e=r===null,f=i.url+(e?"/connect":"");i.pollXhr=n.ajax(f,{type:"POST",data:{clientId:i.clientId,messageId:r,connectionData:i.data,transport:"longPolling",groups:(i.groups||[]).toString()},dataType:"json",success:function(r){var f=0;r&&(r.Messages&&n.each(r.Messages,function(){try{n(i).trigger("onReceived",[this])}catch(t){console&&console.log&&console.log("Error raising received "+t)}}),i.messageId=r.MessageId,n.type(r.TransportData.LongPollDelay)==="number"&&(f=r.TransportData.LongPollDelay),i.groups=r.TransportData.Groups),f>0?t.setTimeout(function(){u(i)},f):u(i)},error:function(r,f){if(f==="abort")return;n(i).trigger("onError",[r]),t.setTimeout(function(){u(i)},2e3)}})})(i),setTimeout(r,150)},250)},send:function(t,i){n.ajax(t.url+"/send",{type:"POST",dataType:"json",data:{data:i,transport:"longPolling",clientId:t.clientId},success:function(i){i&&n(t).trigger("onReceived",[i])},error:function(i,r){if(r==="abort")return;n(t).trigger("onError",[i])}})},stop:function(n){n.pollXhr&&(n.pollXhr.abort(),n.pollXhr=null)}}},i.noConflict=function(){return n.connection===i&&(n.connection=r),i},n.connection&&(r=n.connection),n.connection=n.signalR=i})(window.jQuery,window)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Authors

Sacha Barber
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
 
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
 
Both of these at Sussex University UK.
 
Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Richard E King
Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 8 Feb 2012
Article Copyright 2012 by Sacha Barber, Richard E King
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid