0

I have a Silverlight 5.0 app which i am trying to connect to a Cross Domain SignalR MVC app with no success. we are using IE 8.Here is what i tried so far.

On the Silverlight side: Silverlight app is hosted under

http://testserver:8088/SilverApp

Added clientaccesspolicy.xml file on root folder.

var conn = new HubConnection("http://testserver:8088/MVC/");
var hub = conn.CreateProxy("SignalRMVC.Hubs.ChatHub");
hub.On<string>("NewMessage", message => Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(message)));
conn.Start();

On the MVC Side: App is hosted under

http://testserver:8088/MVC

I added these code.

namespace SignalRMVC.Hubs
{
    public class ChatHub:Hub
    {
        public void SendMessage(string message)
        {
            Clients.All.NewMessage(message);
        }
    }
}    
    var hubConfiguration = new HubConfiguration();
    hubConfiguration.EnableCrossDomain = true;
    RouteTable.Routes.MapHubs(hubConfiguration)

Please let me know if i am missing anything ! I have reached a roadblock in deploying my application and i cant proceed further without fixing this issue.

Thanks !

[Update] I was able to finally make it work. I was using an older version of Silverlight SignalR Client dll. I updated to new one. I also changed the code to use

hub = conn.CreateHubProxy("ChatHub"); 

instead of conn.CreateProxy("SignalRWeb.Hubs.ChatHub");

I also had to copy the clientaccesspolicy.xml file under the the MVC SignalR root folder. This worked great under localhost, but when i moved the code to host under IIS, its throwing an error The Start method must be called before the data can be send.

I am starting the connection like:

conn.Start().ContinueWith(task => { if (task.IsFaulted) {

      }
      else
      {}
  });

and on button click i call,

hub.Invoke("SendMessage", "Test");

and that is where it throws this error.

I am using Windows Authentication and .Net 4.0,

Thanks !

4

0 回答 0