0

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 ?

K9 Code
  • 53
  • 5
  • I'm guessing that Windows Phone (Windows Runtime) apps have the restriction that they cannot connect to other processes on localhost. See [this post](http://stackoverflow.com/questions/26531657/why-not-connect-from-winrt-appon-streamsocket-to-win32-appon-qtcpsocket) for a discussion on the restrictions for Windows 8 (not phone) store apps. – chue x Nov 14 '14 at 17:28
  • no, that problem occurs when connecting to some other app. I am retrieving data from webService. Its not an app. I have successfully received a string. But objects and lists are not received. I was asking for possible ways to receive objects and collections. – K9 Code Nov 17 '14 at 05:01

0 Answers0