下面的小代码在控制台应用程序中工作得很好,但是在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 vers。4.13.0 (=最新稳定)进入我的Visual 2015 Silverlight项目。
发布于 2016-01-06 09:45:39
将以下代码添加到MainPage构造函数中,就在InitializeComponent()之后:
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/
发布于 2015-12-21 12:59:11
试试这个:
var Meter = await client
.For<MyEntityName>()
.Top(1)
.FindEntryAsync();发现这里
https://stackoverflow.com/questions/34395747
复制相似问题