自托管 ADO.NET 数据服务,从外部 Silverlight 应用程序使用
问题:
存在一个问题,我无法从 RIA 应用程序访问我的自托管 ADO.NET 数据服务。
我的服务通过富互联网应用程序 (RIA) 单独托管到 Web 项目。
我需要启用从单独 Silverlight(和Flash)客户端应用程序的访问。
在 Silverlight 中,当我尝试调用 ADO.NET 数据服务(单独自托管)时,出现异常(见下文)。我相信这是由于 Silverlight 禁止跨域调用。
System.InvalidOperationException:保存更改时发生错误。有关详细信息,请参阅内部异常。 ---> System.Data.Services.Http.WebException:“HttpWebResponse.NormalizeResponseStatus”发生内部错误。 在 System.Data.Services.Http.HttpWebResponse.NormalizeResponseStatus(Int32& statusCode) 在System.Data.Services.Http.HttpWebResponse..ctor(HttpWebRequest请求,Int32状态代码,字符串responseHeaders) 在 System.Data.Services.Http.HttpWebRequest.CreateResponse() 在 System.Data.Services.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Data.Services.Client.QueryAsyncResult.AsyncEndGetResponse(IAsyncResult asyncResult) --- 内部异常堆栈跟踪结束 --- 在 System.Data.Services.Client.BaseAsyncResult.EndExecute[T](对象源,字符串方法,IAsyncResult asyncResult) 在 System.Data.Services.Client.QueryAsyncResult.EndExecute[TElement](对象源,IAsyncResult asyncResult) 在 System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult) 在 Curo.Silverlight.MainPage.<>c__DisplayClass1.<.ctor>b__0(IAsyncResult ar) 在 System.Data.Services.Client.BaseAsyncResult.HandleCompleted() 在 System.Data.Services.Client.QueryAsyncResult.AsyncEndGetResponse(IAsyncResult asyncResult) 在 System.Data.Services.Http.HttpWebRequest.ReadyStateChanged() System.Data.Services.Http.WebException:“HttpWebResponse.NormalizeResponseStatus”发生内部错误。 在 System.Data.Services.Http.HttpWebResponse.NormalizeResponseStatus(Int32& statusCode) 在System.Data.Services.Http.HttpWebResponse..ctor(HttpWebRequest请求,Int32状态代码,字符串responseHeaders) 在 System.Data.Services.Http.HttpWebRequest.CreateResponse() 在 System.Data.Services.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在 System.Data.Services.Client.QueryAsyncResult.AsyncEndGetResponse(IAsyncResult asyncResult)
注释:
据我所知,对于 ADO.NET 数据来说,跨域访问似乎是被禁止的服务,这可能导致我必须采取另一种方法来访问数据,例如使用纯 REST 框架..?
《ADO.NET跨域问题》 数据服务比它更复杂 声音还没有解决。 我已经和微软讨论过这个问题了 而现在以及它的原因 不起作用与其使用有关 浏览器级传输 运输不允许跨站点 脚本。”
参见: http://forums.silverlight.net/forums/p/70925/ 170703.aspx#170703
我知道我可能需要公开一个 ClientAccessPolicy.xml 文件,该文件将定义访问规则,同时限制跨站点脚本编写。
还值得注意的是,RIA 应用程序将在同一 LAN 上运行。
问题:
考虑到 RIA 客户端将在同一防火墙后面运行,我是否有可行的方法来访问它们的服务?如果是这样怎么办?
如何准确地从自托管 ADO.NET 数据服务公开 ClientAccessPolicy.xml?
您建议采取什么方式继续以允许外部访问我的服务? - 不同的REST框架? - 以分离为代价在同一 Web 项目中托管服务? - 还有其他建议吗...
谢谢。
Issue:
An issue exists whereby I cannot access my Self Hosted ADO.NET Data Services from my RIA applications.
My services are hosted separately to the web projects with the Rich Internet Applications (RIA)s.
I need to enable access from separate Silverlight (and Flash) client apps.
From Silverlight I get an exception (see below) when I try to make a call to the ADO.NET Data Service (which is Self Hosted separately). This I believe to due to Silverlight forbidding the cross domain call.
System.InvalidOperationException: An error occurred while saving changes. See the inner exception for details. --->
System.Data.Services.Http.WebException: Internal error at 'HttpWebResponse.NormalizeResponseStatus'.
at System.Data.Services.Http.HttpWebResponse.NormalizeResponseStatus(Int32& statusCode)
at System.Data.Services.Http.HttpWebResponse..ctor(HttpWebRequest request, Int32 statusCode, String responseHeaders)
at System.Data.Services.Http.HttpWebRequest.CreateResponse()
at System.Data.Services.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.QueryAsyncResult.AsyncEndGetResponse(IAsyncResult asyncResult)
--- End of inner exception stack trace ---
at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at System.Data.Services.Client.QueryAsyncResult.EndExecute[TElement](Object source, IAsyncResult asyncResult)
at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
at Curo.Silverlight.MainPage.<>c__DisplayClass1.<.ctor>b__0(IAsyncResult ar)
at System.Data.Services.Client.BaseAsyncResult.HandleCompleted()
at System.Data.Services.Client.QueryAsyncResult.AsyncEndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Http.HttpWebRequest.ReadyStateChanged()
System.Data.Services.Http.WebException: Internal error at 'HttpWebResponse.NormalizeResponseStatus'.
at System.Data.Services.Http.HttpWebResponse.NormalizeResponseStatus(Int32& statusCode)
at System.Data.Services.Http.HttpWebResponse..ctor(HttpWebRequest request, Int32 statusCode, String responseHeaders)
at System.Data.Services.Http.HttpWebRequest.CreateResponse()
at System.Data.Services.Http.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Data.Services.Client.QueryAsyncResult.AsyncEndGetResponse(IAsyncResult asyncResult)
Notes:
From what I have read, it appears that cross domain access is forbidden with regards to ADO.NET Data Services, which may result in my having to take another approach to the data access e.g. using a pure REST Framework..?
"The problem of Cross Domain ADO.NET
Data Services is more complex than it
sounds and it hasn't been solved.
I've discussed it with Microsoft for a
while now and the reason that it
doesn't work has to do with its using
a browser level transport and that
transport doesn't allow cross-site
scripting."See:
http://forums.silverlight.net/forums/p/70925/170703.aspx#170703
I understand that I need may need to expose a ClientAccessPolicy.xml file which will define the access rules whilst restricting cross site scripting.
It is also noteworthy to mention that the RIA applications will be running on the same LAN.
Questions:
Is there a viable means for me to access the services from my RIA clients considering they will be running behind the same firewall? If so how?
How do I expose ClientAccessPolicy.xml from a Self Hosted ADO.NET Data Service exactly?
What way would you recommend proceeding in order to allow external access to my services?
- Different REST Framework?
- Host Services within same web project at the cost of separation?
- Any other advice...
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否完全理解您的问题,但至少,我会确保在 service。 xml 策略文件位于域的根文件夹中非常重要。例如,如果您的服务托管在 mycompany.com/services 中,则 xml 文件需要位于 mycompany.com 文件夹中,而不是 services 文件夹中。
这是 ClientAccessPolicy.xml 的示例:
这是 crossdomain.xml 的示例:
我建议对 flash 和 silverlight 使用这两个文件。上面的两个文件都允许从所有 flash 和 silverlight 应用程序进行开放访问,但如果您位于防火墙后面,这应该不是问题。
我在防火墙后的 silverlight 应用程序之一中遇到了这个问题,将这些文件放在适当的位置似乎可以解决该问题。我将从这些文件开始,然后从那里开始。
I'm not sure I understand the full breadth of your problem, but at the very least, I would make sure I had a clientaccesspolicy.xml file and a crossdomain.xml file in the root folder of the service. It's important for the xml policy files to be in the root folder of the domain. For example, if your service is hosted in mycompany.com/services, the xml files need to be in the mycompany.com folder, not the services folder.
Here's an example of the ClientAccessPolicy.xml:
And here's an example of the crossdomain.xml:
I would recommend using both files for both flash and silverlight. Both files above will allow open access from all flash and silverlight apps, but that shouldn't be a problem if you're behind a firewall.
I had this exact problem in one of my behind-the-firewall silverlight apps and putting these files in place seemed to fix the problem. I would start with these files and go from there.
“跨域 ADO.NET 数据服务的问题比听起来更复杂,而且还没有得到解决。我已经与 Microsoft 讨论了一段时间,它不起作用的原因与它的使用浏览器级传输,并且该传输不允许跨站点脚本。”
请参阅:http://forums.silverlight.net/forums/p/ 70925/170703.aspx#170703
需要跨域策略(如上面 Ben McCormack 的回答所示)。
通过利用设置为允许跨域访问聚合源的 Yahoo 管道,您可以在 Silverlight 应用程序中使用外部 ADO.NET 数据服务(以前的 Astoria,现在的 OData)。
您很可能会失去查询 Odata 为您提供的数据集的保真度,但这可以在 yahoo 管道中重新创建。
问题不在于 ADO.NET 数据服务 (OData),而在于 Silverlight,因为它不允许跨域调用。
"The problem of Cross Domain ADO.NET Data Services is more complex than it sounds and it hasn't been solved. I've discussed it with Microsoft for a while now and the reason that it doesn't work has to do with its using a browser level transport and that transport doesn't allow cross-site scripting."
See: http://forums.silverlight.net/forums/p/70925/170703.aspx#170703
The cross domain policy is required by (as shown in the answer by Ben McCormack above).
By utilizing Yahoo pipes which is set up to allow cross domain access to aggregated feeds, you may be able to consume and external ADO.NET Data Services (formerly Astoria, now OData) from within a Silverlight application.
You will most likely lose the fidelity of querying the dataset that Odata gives you, but this could be recreated in the yahoo pipes.
The issue was not with the ADO.NET data services (OData), its was with Silverlight as does not allow cross domain calls.