I want to send an observablecollection object through a WCF service and receive it in windows phone 8 app. the service Is as below.
public ObservableCollection<State> GetName()
{
StateEntities objEntities = new StateEntities();
ObservableCollection<State> stateCollection = new ObservableCollection<State>();
foreach (State s in objEntities.States)
{
stateCollection.Add(s);
}
return stateCollection;
}
State is a Class having data from the table. The contract is given below
public interface IHost
{
[OperationContract]
string DoWork();
[OperationContract]
ObservableCollection<State> GetName();
}
Now I want to consume the service in a windows phone app. A button click should trigger the service consumption , get data from the service as observable collection and feed it into a gridview.
public sealed partial class MainPage : Page
{
ServiceReference1.HostClient proxy;
public MainPage()
{
proxy = new HostClient();
this.InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
ObservableCollection<State> stateCollection = new ObservableCollection<State>();
stateCollection = await proxy.GetNameAsync();
dataGrid.ItemsSource = stateCollection;
}
}
but it is throwing and exception in the await line. This is the exception.
An exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll but was not handled in user code
Additional information: An error occurred while receiving the HTTP response to "ttp://localhost:65338/Host.svc." This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server
Can anybody suggest an alternative or solution ?