我有一个Silverlight 5应用程序正在调用OData服务(OOTB与SharePoint 2010一起使用)以从列表中提取数据。使用Windows身份验证保护站点。当我运行测试时,系统会提示我登录,但结果总是说结果集中返回的结果为零。
现在这就是奇怪的。我知道列表中有数据(当我手动插入OData请求URL时,我看到结果在浏览器中返回)。当我在运行测试时观察Fiddler时,我看到了一些对clientaccesspolicy.xml的请求(所有这些都是401响应)...然后我登录&它成功获取clientaccesspolicy.xml文件。但是,即使应用程序说它运行查询并返回零结果,我也没有在Fiddler中看到实际的OData服务请求(在成功调用clientaccesspolicy.xml之后没有任何内容。
这是代码的样子:
private DataServiceCollection<InstructorsItem> _dataCollection = new DataServiceCollection<InstructorsItem>();
private Action<IEnumerable<Instructor>> _callbackWithData;
/// <summary>
/// Retrieves a list of instructors from the data service.
/// </summary>
public void GetInstructors(Action<IEnumerable<Instructor>> callback) {
// save callbacks
ResetCallbacks();
_callbackWithData = callback;
// get the instructors
var query = from instructor in IntranetContext.Instructors
select instructor;
// execute query
RunQuery(query);
}
/// <summary>
/// Retrieves instructors from the data source based on the specified query.
/// </summary>
/// <param name="query">Query to execute</param>
private void RunQuery(IQueryable<InstructorsItem> query) {
// clear the collection & register the load completed method
_dataCollection.Clear();
_dataCollection.LoadCompleted += OnLoadDataCompleted;
// fire the load
_dataCollection.LoadAsync(query.Take(5));
}
/// <summary>
/// Handler when the data has been loaded from the service.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnLoadDataCompleted(object sender, LoadCompletedEventArgs e) {
// remove the event handler preventing double loads
_dataCollection.LoadCompleted -= OnLoadDataCompleted;
// convert the data to a generic list of objects
var results = _dataCollection.ToList<InstructorsItem>();
// TODO: convert results to local objects
List<Instructor> convertedResults = new List<Instructor>();
foreach (var item in results) {
convertedResults.Add(new Instructor() {
SharePointId = item.Id,
Name = item.Title
});
}
// run the callback
_callbackWithData(convertedResults);
}
这就是测试运行器看起来像触发它的东西:
[TestMethod]
[Asynchronous]
[Description("Test loading instructors from the OData Intranet service.")]
public void TestGetInstructors() {
bool asyncCallCompleted = false;
List<Instructor> result = null;
// call data service
_dataService.GetInstructors(asyncResult => {
asyncCallCompleted = true;
result = new List<Instructor>(asyncResult);
});
// run test when call completed
EnqueueConditional(() => asyncCallCompleted);
EnqueueCallback(
() => Assert.IsTrue(result.Count > 0, "Didn't retrieve any instructors."));
EnqueueTestComplete();
}
不能为我的生活弄清楚(1)为什么我没有看到Fiddler中的查询显示没有错误,实际上它说运行测试时没有错误。
答案 0 :(得分:0)
如果您在同一台计算机上运行服务器和客户端,则没有外部HTTP流量,因此Fiddler无法接收。