【发布时间】:2015-03-07 23:45:24
【问题描述】:
我能够从本地主机在我的 Windows Phone 应用程序上添加我的 Odata 服务服务引用,但是当我知道当我使用 Northwind 服务引用时我可以获取数据时,我无法获取数据集合需要的数据,我什至检查了服务版本,我认为这是兼容性的问题?但我仍然不确定这里发生了什么,因为我没有任何错误。我正在尝试使用提琴手获得服务响应,但我不知道我的方向是否正确,请帮忙???我在 Visual Studio 2010 上使用 Odata 服务 V3,我正在尝试从 IIS(本地主机)上的 VS express 2012 中使用它。!!! :(((同一个项目在服务器和本地主机上的 LinqPad4 上运行良好)
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using TestConsumeWebService.Resources;
using TestConsumeWebService.Northwind;
using System.Data.Services.Client;
using TestConsumeWebService.DataService;
namespace TestConsumeWebService
{
public partial class MainPage : PhoneApplicationPage
{
private static readonly Uri _rootUri =
new Uri("http://localhost:88/DataService.svc/");
//// Define the typed DataServiceContext.
//private DataEntities _context;
// Define the binding collection for Customers.
private DataServiceCollection<Table> _customers;
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var _context = new DataEntities(_rootUri);
Customers = new DataServiceCollection<Table>(_context);
// Specify an OData query that returns all customers.
var query = from cust in _context.Table
select cust;
// Load the customer data.
Customers.LoadAsync(query);
}
public DataServiceCollection<Table> Customers
{
get { return _customers; }
private set
{
// Set the Titles collection.
_customers = value;
// Register a handler for the LoadCompleted callback.
_customers.LoadCompleted += OnCustomersLoaded;
// Raise the PropertyChanged events.
}
}
// Handles the DataServiceCollection<T>.LoadCompleted event.
private void OnCustomersLoaded(object sender, LoadCompletedEventArgs e)
{
// Make sure that we load all pages of the Customers feed.
if (Customers.Continuation != null)
{
Customers.LoadNextPartialSetAsync();
}
}
}
}
这是我的 Odata 服务代码:
public class DataService : DataService<DataEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.UseVerboseErrors=true;
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
【问题讨论】:
-
请向我们展示您的代码以获得帮助。
-
好的,我已经添加了我的代码!请帮忙!!谢谢!
标签: c# visual-studio-2010 windows-phone-8 wcf-data-services