Click here to Skip to main content
15,886,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Am playing with a wcf service,silverlight and ASP.Net.
Now am trying to populate a dropdownlist using an event handled by a button. the page works but whn i click the button i get the following error:

An error occurred while trying to make a request to URI 'http://localhost:49271/BusinessLayerService.svc'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute. Please see the inner exception for more details.

What should i do?

Check my code below.

Below is my BusinessLayer.svc
public class BusinessLayerService : IBusinessLayerService
    {
        String ConnectionString;

        public String CONNECTIONSTRING
        {
            get { return ConnectionString; }
            set { ConnectionString = value; }
        }
        
        public void BusinessLayerServiceConnection()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;

        }
        
        //load ddlServices
        public List<ClsAppointmentServices> ddlServices()
        {
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("procGetAppointmentType", con);
                cmd.CommandType = CommandType.StoredProcedure;


                List<ClsAppointmentServices> myList = new List<ClsAppointmentServices>();

                try
                {
                    con.Open();
                    SqlDataReader read = cmd.ExecuteReader();
                    while (read.Read())
                    {
                        ClsAppointmentServices service = new ClsAppointmentServices(Convert.ToInt32(read["TypeID"]), Convert.ToString(read["Services"]));
                        myList.Add(service);

                    }
                    read.Close();

                }
                catch (Exception exp)
                {
                    throw new ApplicationException(exp.Message);
                }

                return myList;
            }
        }
    }

Below is my Interface.cs
CSS
namespace SilverlightAppointmentSystem
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IBusinessLayerService" in both code and config file together.
    [ServiceContract]
    public interface IBusinessLayerService
    {
        [OperationContract]
        List<ClsAppointmentServices> ddlServices();
    }
}

Below is the client side, silverlight MainPage.xaml.cs
namespace Anele
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

            BusinessLayerService.BusinessLayerServiceClient Bl = new BusinessLayerService.BusinessLayerServiceClient();

            Bl.ddlServicesAsync();
            Bl.ddlServicesCompleted += new EventHandler<ddlServicesCompletedEventArgs>(Bl_ddlServicesCompleted);

        }

        void Bl_ddlServicesCompleted(object sender, ddlServicesCompletedEventArgs e)
        {
            List<ClsAppointmentServices> userList = new List<ClsAppointmentServices>();
            comboBox1.SelectedValuePath = "UserID";
            comboBox1.DisplayMemberPath = "UserID";
            comboBox1.ItemsSource = userList;
        }
    }
}
Posted
Updated 20-Jul-11 21:09pm
v2
Comments
Mark Salsbery 21-Jul-11 14:57pm    
Is the Silverlight application hosted in the same domain (http://localhost:49271) as the service?
Anele Ngqandu 22-Jul-11 6:45am    
not realy sure sir...but some one said to me "The Silverlight app cannot find your clientaccesspolicy.xml file. If you don't have one, create one. But even then you might run into trouble if you are using Visual Studio's built-in web server, which it appears you are. You need to make sure the service port's properties are the same as whatever the autogenerated port is" and i realy dont have a clue on how to do that
Anele Ngqandu 10-Aug-11 5:36am    
Where should i go to change host domain, so that my silverlight and service should host in the same domain?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900