在 Silverlight 4 中使用 JSON REST 服务
我需要在 Silverlight 应用程序中使用 JSON REST 服务,以便可以在 Silverlight 应用程序中显示来自 REST 服务的信息。下面是我的代码,但 ClientDownloadStringCompleted() 从未进入,我不知道为什么。 REST 服务确实有数据并且正在运行。我似乎无法访问它,因此我可以解析出我需要的数据。 JSON 服务视图
string jsonlink = "http://hou-prodserver2/ArcGIS/rest/services/sar/ScheduledRig/MapServer/81/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=MAXDATE%3E%271%2F1%2F1900%27&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=MAXDATE&f=pjson";
var client = new WebClient();
client.DownloadStringCompleted += ClientDownloadStringCompleted;
client.DownloadStringAsync(new Uri(jsonlink, UriKind.Absolute));
下面是我尝试用来访问数据的方法但它从未被使用过
private void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//handle the response.
string result = e.Result;
}
I need to use a JSON REST Service inside my Silverlight Application so that I can display information from the REST service in my Silverlight App. Below is my code but the ClientDownloadStringCompleted() is never stepped into and I'm not sure why. The REST service does have data and is working. I just can't seem to access it so I can parse out the data I need. View of the JSON Service
string jsonlink = "http://hou-prodserver2/ArcGIS/rest/services/sar/ScheduledRig/MapServer/81/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=MAXDATE%3E%271%2F1%2F1900%27&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=MAXDATE&f=pjson";
var client = new WebClient();
client.DownloadStringCompleted += ClientDownloadStringCompleted;
client.DownloadStringAsync(new Uri(jsonlink, UriKind.Absolute));
Below is Method I'm trying to use to get access to the data but it never gets used
private void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//handle the response.
string result = e.Result;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保服务站点的根目录中有以下一个或两个文件:
crossdomain.xml
clientaccesspolicy.xml
如果您的 Silverlight 应用程序不是在与服务相同的域中,这些文件需要存在才能允许其连接。如果不这样做,Silverlight 就会默默地失败。
Make sure that service site has one or both of the following files at the root of the site:
crossdomain.xml
clientaccesspolicy.xml
If your Silverlight app is not on the same exact domain as the service, those files need to exist to allow it to connect. If they don't Silverlight fails silently.