2

チャネル uri が Windows Phone 8 エミュレーターで作成されていません。コードは次のとおりです。

   `private void OnChannelUriChanged(Uri value)
    {
        Dispatcher.BeginInvoke(() =>
        {
            txtURI.Text = value.ToString();
        });

        Debug.WriteLine("URI: " + value.ToString());
    }

    private static void BindToShell(HttpNotificationChannel httpChannel)
    {
        try
        {
            httpChannel.BindToShellToast();
        }
        catch (Exception)
        {
        }
    }
    void httpChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
    {
        Dispatcher.BeginInvoke(() =>
        {
            txtURI.Text = "Toast Notification Message Received: ";
            if (e.Collection != null)
            {
                Dictionary<string, string> collection = (Dictionary<string, string>)e.Collection;
                System.Text.StringBuilder messageBuilder = new System.Text.StringBuilder();
                foreach (string elementName in collection.Keys)
                {
                    txtURI.Text += string.Format("Key: {0}, Value:{1}\r\n", elementName, collection[elementName]);
                }
            }
        });
    }
    void httpChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {
        //You get the new Uri (or maybe it's updated)
        OnChannelUriChanged(e.ChannelUri);
    }

    private void SetupChannel()
    {
        HttpNotificationChannel httpChannel = null;
        string channelName = "DemoChannel";

        //if channel exists, retrieve existing channel
        httpChannel = HttpNotificationChannel.Find(channelName);

        if (httpChannel != null)
        {
            //If we cannot get Channel URI, then close the channel and reopen it
            if (httpChannel.ChannelUri == null)
            {
                httpChannel.UnbindToShellToast();
                httpChannel.Close();
                SetupChannel();
                return;
            }
            else
            {
                OnChannelUriChanged(httpChannel.ChannelUri);
            }
            BindToShell(httpChannel);
        }
        else
        {
            httpChannel = new HttpNotificationChannel(channelName);
            httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
            httpChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(httpChannel_ShellToastNotificationReceived);
            httpChannel.Open();
            BindToShell(httpChannel);
        }
    }

    private void btnCreateChannel_Click(object sender, RoutedEventArgs e)
    {
        SetupChannel();
    }`

誰でもこの問題を解決するための解決策を送ってもらえますか ありがとう

4

1 に答える 1