Modules and Service References

Topics: Prism v2 - Silverlight 2
Feb 27, 2009 at 3:27 PM
Do I need to create a Service Reference and a ServiceReferences.ClientConfig file in each module or can I create one in the main module and reference that one?
Feb 27, 2009 at 6:47 PM

If you use a method similiar to that shown in GetEmployeeList() below you won't require a configuration file at all; I delete them from my projects/modules after doing an "Add Web Refererence" or "Update Web Reference": 

See http://www.CodePlex.com/SDMS for the application the following is an excerpt from:

namespace SDMS.DataLayer
{
    public class EmployeeProviderDAL : IEmployeeProviderDAL
    {
        public event EventHandler<EmployeeEventArgs> OnEmployeeEvent;
        private IUnityContainer container;

        public EmployeeProviderDAL(IUnityContainer container)
        {
            this.container = container;
        }

        public void GetEmployeeList()
        {
            try
            {
                IServerConfiguration config = container.Resolve<IServerConfiguration>();

                // Use basic HttpBinding on both Silverlight and Desktop
                BasicHttpBinding binding =
                    new BasicHttpBinding(BasicHttpSecurityMode.None);

                binding.Name = "bndDoctorService";

                // Get the WebServiceURI from the unity container
                Uri baseAddress = new Uri(config.WebServiceURI_DEV);

                EndpointAddress address = new EndpointAddress(baseAddress);

                ServicesClient client = new ServicesClient(binding,address);

                client.GetEmployeeListCompleted +=
                    new EventHandler<GetEmployeeListCompletedEventArgs>
                        (client_GetEmployeeListCompleted);

                client.GetEmployeeListAsync();
            }
            catch (Exception ex)
            {
                HtmlPage.Window.Alert(string.Format(
                    "EmployeeService.GetEmployeeList() encountered the following error!" +
                    "\r\n\r\n{0}{1}", ex.Message, ex.StackTrace));
            }
        }

        void client_GetEmployeeListCompleted(object sender,
            GetEmployeeListCompletedEventArgs e)
        {
            EmployeeEventArgs args = new EmployeeEventArgs();
            ObservableCollection<EmployeeData> empData =
                ((GetEmployeeListCompletedEventArgs)e).Result;

            args.EmployeeList = new ObservableCollection<Employee_Data>();
            foreach(EmployeeData record in empData)
            {
                args.EmployeeList.Add(new Employee_Data
                {
                    DisplayValue = record.DisplayValue,
                    EmployeeID = record.EmployeeID,
                    FirstName = record.FirstName,
                    LastName = record.LastName
                });
            }

            if (OnEmployeeEvent != null)
                OnEmployeeEvent(this, args);
        }
    }
}