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;
}
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
namespace SilverlightAppointmentSystem
{
[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;
}
}
}