locked
Silverlight App disappears when WCF Service is called when the App is hosted on Win 2K3. RRS feed

  • Question

  • Hi,

    I have a WCF service called by my Silverlight app that runs just fine when I debug in Visual Studio.  However when I Build --> Publish & host the app on Win 2K3, the app disappears from the browser once the service is called.

    Am I missing something simple that would create this scenario?  The app is just a stub that I'm using to understand how to use a WCF service to get the current user name.  The primary code follows:

    XAML Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    namespace SilverlightApplication3
    {
        public partial class Page : UserControl
        {
            String alias = "";

            public Page()
            {
                InitializeComponent();
            }

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                ServiceReference1.Service1Client client = new SilverlightApplication3.ServiceReference1.Service1Client();
                client.GetCurrentUserCompleted += new EventHandler<SilverlightApplication3.ServiceReference1.GetCurrentUserCompletedEventArgs>(client_GetCurrentUserCompleted);
                client.GetCurrentUserAsync();
            }

            void client_GetCurrentUserCompleted(object sender, SilverlightApplication3.ServiceReference1.GetCurrentUserCompletedEventArgs e)
            {
                alias = e.Result;
                Button.Content = alias;
            }
        }
    }

     

    WCF Service Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.Security.Principal;

    namespace SilverlightApplication3_Web
    {
        // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config.
        public class Service1 : IService1
        {
            public String GetCurrentUser()
            {
                try
                {
                    WindowsPrincipal w = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                    string alias = w.Identity.Name;
                    return alias;
                }
                catch (NullReferenceException e)
                {
                    return "Null";
                }
            }
        }
    }

    Thanks,

    -fudog

    Tuesday, April 29, 2008 8:08 PM

Answers

  • Hello, maybe you've encountered a cross domain issue. Make sure your Silverlight application and the WCF service are hosted on the same server and the same port. Or you'll need a cross domain policy file as described here.

     

    Thursday, May 1, 2008 12:05 AM