Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems sending message between Silverlight apps
    primarykey
    data
    text
    <p>Has anyone had any issues communicating between two Silverlight apps. When I try to send a message from one app, I get an error, "The message could not be delivered to receiver." My code for sending is below. I'm using the similar code that is in the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E565FC92-D5F6-4F5F-8713-4DD1C90DE19F&amp;displaylang=en" rel="nofollow noreferrer">samples</a> for implementing Windows Live ID in a Silverlight App. I have this working when I'm running locally, but when I post to the server, I'm getting the delivery error.</p> <pre><code> #region Fields private readonly LocalMessageSender sender = new LocalMessageSender("LiveIdAuthentication"); private int attempts = 0; private const int MAX_ATTEMPTS = 10; #endregion #region Constructors public MainPage() { InitializeComponent(); this.sender.SendCompleted += new EventHandler&lt;SendCompletedEventArgs&gt;(Sender_SendCompleted); this.SendMessage("authenticated"); } #endregion #region Event Handlers private void Sender_SendCompleted(object sender, SendCompletedEventArgs e) { if (e.Error != null) { if (attempts &gt; MAX_ATTEMPTS) { MessageBox.Show(e.Error.Message); CloseWindow(); } else { SendMessage("authenticated"); } } else { attempts = 0; CloseWindow(); } } #endregion #region Methods private void SendMessage(string message) { attempts++; this.sender.SendAsync(message); } private void CloseWindow() { HtmlPage.Window.Eval("window.open(\"about:blank\", \"_self\")"); HtmlPage.Window.Eval("window.close()"); } #endregion </code></pre> <p>Sorry about forgetting the receiver. This is mostly from the Live ID example.</p> <pre><code> private readonly WindowsLiveIdAuthentication _service; private readonly AsyncCallback _asyncCallback; private readonly object _asyncState; private readonly LocalMessageReceiver _receiver = new LocalMessageReceiver("LiveIdAuthentication"); private bool _isCompleted; private LoadUserResult _result; #region Constructors public LoginAsyncResult(WindowsLiveIdAuthentication service, AsyncCallback asyncCallback, object asyncState) { this._service = service; this._asyncCallback = asyncCallback; this._asyncState = asyncState; this._receiver.MessageReceived += this.LocalMessageReceived; } #endregion #region Properties public object AsyncState { get { return this._asyncState; } } public System.Threading.WaitHandle AsyncWaitHandle { get { throw new NotImplementedException(); } } public bool CompletedSynchronously { get { return false; } } public bool IsCompleted { get { return this._isCompleted; } } public LoadUserResult Result { get { return this._result; } } #endregion #region Methods public void Cancel() { if (!this._isCompleted) { this._isCompleted = true; } } public void Complete() { if (!this._isCompleted) { this._isCompleted = true; this._receiver.Dispose(); Application.Current.RootVisual.Dispatcher.BeginInvoke(() =&gt; { if (this._asyncCallback != null) { this._asyncCallback(this); } }); } } #endregion #region Event Handlers public void HandleLoadCallback(IAsyncResult asyncResult) { this._result = this._service.EndLoadUser(asyncResult); if (!this._result.User.Identity.IsAuthenticated &amp;&amp; !this._isCompleted &amp;&amp; (this != asyncResult.AsyncState)) { this._receiver.Listen(); } else { this.Complete(); if (Globals.CurrentUser == null) { Globals.CurrentUser = _result.User as User; Globals.SelectedDate = DateTime.Now; (App.Current.RootVisual as MainPage).SetTheme(Globals.CurrentUser.CurrentTheme); HtmlPage.Window.Navigate(new Uri("#UserHome", UriKind.Relative)); } } } private void LocalMessageReceived(object sender, MessageReceivedEventArgs e) { this._service.BeginLoadUser(this.HandleLoadCallback, this); } #endregion </code></pre> <p>UPDATE: OK, I found out that a RIA service call had failed, which resulted in not calling receiver.Listen(). So there wasn't a receiver for the sender to send messages. I'm still working on the failed RIA service call, but that's a different issue. I'll mark this as answered.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload