0

以下一小段代码在控制台应用程序中运行良好,但在 Silverlight 5 应用程序中(我需要它!)它通过抛出NotSupportedException失败:

    var client = new ODataClient("http://MYSERVER:9000/OData_v4/ProductionDb/");

    try
    {
        //This statement throws in Silverlight 5 but not in a .NET 4.5 Console application!!??
        var Meter = await client
            .For("MyEntityName")
            .Top(1)
            .FindEntryAsync();

        foreach (var entry in Meter)
            Debug.WriteLine(string.Format("{0}: {1}", entry.Key, entry.Value));
    }
    catch (NotSupportedException ex)
    {
        Debug.WriteLine(string.Format( "Exception {0}: {1} ", ex.GetType().ToString(), ex.Message ));
    }

为什么它在 Silverlight 中不起作用?根据文档,它应该可以直接与 Silverlight 一起使用......?

我使用 NuGet 安装Simple.OData.Client版本。4.13.0(=最新稳定版)到我的 Visual Studio 2015 Silverlight 项目中。

4

2 回答 2

0

尝试这个 :

var Meter = await client
            .For<MyEntityName>()
            .Top(1)
            .FindEntryAsync();

在这里找到

于 2015-12-21T12:59:11.350 回答
0

在 InitializeComponent() 之后,将以下代码添加到 MainPage 构造函数:

HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
HttpWebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);

这应该可以解决问题(至少如果我能够通过这些更改运行您的代码)。非常令人沮丧,但与 OData 库无关。您可以在此处阅读有关此问题的更多信息:https ://mattduffield.wordpress.com/2011/12/11/silverlight-specified-method-is-not-supported-on-this-request/

于 2016-01-06T09:45:39.060 回答