Search code examples
c#wcfwcf-data-services

Consuming WCF Data Services


I tried to consume a wcf data service reference I made earlier. everything was in order until I tried to load the data in a datagrid in the client, but it only load the column header. no data being loaded, although the database are filled with data.

there are no error was being thrown by visual studio.

Here are the codes and the screenshot on what's going on

namespace AccountingApplication.Views.Invoices
{
    public partial class InvoicePages : Page
    {
        InventoryEntities SalesOrderHeaderContext = new InventoryEntities(new Uri("http://localhost:9090/EntityDataServices/EntityDataServices.svc/"));
        DataServiceCollection<SalesOrderHeader> SalesOrderCollection = new DataServiceCollection<SalesOrderHeader>();

        public InvoicePages()
        {
            InitializeComponent();

            LoadSalesOrderHeader();
        }

        private void LoadSalesOrderHeader()
        {
            SalesOrderCollection.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(SalesOrderCollection_loadCompleted);
            var soQuery = from salesOrder in SalesOrderHeaderContext.SalesOrderHeaders 
                          select salesOrder;
            SalesOrderCollection.LoadAsync(soQuery );
        }

        private void SalesOrderCollection_loadCompleted(object sender, LoadCompletedEventArgs e)
        {
            SalesOrderHeaderRadGridView.ItemsSource = SalesOrderCollection.ToList();
            testDG.ItemsSource = SalesOrderCollection;
        }
    }
}

enter image description here


Solution

  • ok apparently almost all tutorial on the internet use these lines as clientaccesspolicy.xml put in like this

    <?xml version="1.0" encoding="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="SOAPAction">
            <domain uri="*"/>
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy> 
    

    this line cause a major issue on this line since silverlight 4

    <allow-from http-request-headers="SOAPAction">
    

    we have to change the http-request-headers="*"> in order to make the web service works.