简体   繁体   English

消费WCF数据服务

[英]Consuming WCF Data Services

I tried to consume a wcf data service reference I made earlier. 我尝试使用我之前制作的WCF数据服务参考。 everything was in order until I tried to load the data in a datagrid in the client, but it only load the column header. 一切正常,直到我尝试将数据加载到客户端的datagrid中,但它仅加载列标题。 no data being loaded, although the database are filled with data. 尽管数据库中已填充数据,但没有数据正在加载。

there are no error was being thrown by visual studio. 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;
        }
    }
}

在此处输入图片说明

This is just an idea, but it seams you pick data from db in this line 这只是一个主意,但是它可以接缝,您可以在这一行中从db中选择数据

var SOQuery = from salesOrder in SalesOrderHeaderContext.SalesOrderHeaders select salesOrder;

yet you do not put SOQuery anywhere. 但是您不会将SOQuery放在任何地方。 I just don't see what you do with selected data. 我只是看不到您对所选数据的处理方式。 You collected data, but you are not using it. 您收集了数据,但没有使用它。 SOQuery should be some kind of list now. SOQuery现在应该是某种列表。 Hope this helps any. 希望这对任何人有帮助。

I've got the answer, but I will need to get some sleep first. 我已经找到了答案,但是我需要先入睡。 I'll post the answer first thing in the morning 我会在第一时间发布答案

ok apparently almost all tutorial on the internet use these lines as clientaccesspolicy.xml put in like this 好的,显然,互联网上的几乎所有教程都将这些行作为clientaccesspolicy.xml放入,就像这样

<?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 自Silverlight 4以来,这条线是这条线的主要问题

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

we have to change the http-request-headers="*"> in order to make the web service works. 我们必须更改http-request-headers =“ *”>才能使Web服务正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM