2010-07-22 4 views
0

Est-ce que quelqu'un a eu des problèmes de communication entre deux applications Silverlight? Lorsque j'essaie d'envoyer un message à partir d'une application, j'obtiens une erreur: "Le message n'a pas pu être transmis au destinataire." Mon code pour l'envoi est ci-dessous. J'utilise le code similaire qui est dans le samples pour implémenter Windows Live ID dans une application Silverlight. J'ai ceci fonctionnant quand je cours localement, mais quand je publie sur le serveur, j'obtiens l'erreur de livraison.Problèmes d'envoi de message entre les applications Silverlight

#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<SendCompletedEventArgs>(Sender_SendCompleted); 
     this.SendMessage("authenticated"); 
    } 
    #endregion 

    #region Event Handlers 
    private void Sender_SendCompleted(object sender, SendCompletedEventArgs e) 
    { 
     if (e.Error != null) 
     { 
      if (attempts > 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 

Désolé pour l'oubli du récepteur. Ceci est principalement à partir de l'exemple Live ID.

 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(() => 
       { 
        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 && !this._isCompleted && (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 

MISE À JOUR: OK, j'ai découvert qu'un appel de service RIA avait échoué, ce qui a donné lieu à ne pas appeler receiver.Listen(). Il n'y avait donc pas de récepteur permettant à l'expéditeur d'envoyer des messages. Je travaille toujours sur l'appel de service RIA échoué, mais c'est un problème différent. Je marquerai ceci comme étant répondu.

Répondre

0

Veuillez également ajouter le code pour le récepteur. C'est une partie très importante de cela. Si le récepteur n'existe pas, par exemple, il échouera.

+0

Comme indiqué ci-dessus, le récepteur n'existait pas. Merci de me donner l'indice de descendre du côté du récepteur. –

Questions connexes