从 Silverlight 调用 WCF 服务
我从 silverlight 调用本地托管的 wcf 服务,并得到以下异常。
Iv 创建了一个 clientaccesspolicy.xml,它位于我的主机的路由中。
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
尝试创建时发生错误 对 URI 的请求 'http://localhost:8005/Service1.svc'。 这可能是由于跨域 配置错误。 请参阅 内部异常以获取更多详细信息。 --->
{System.Security.SecurityException ---> 系统.安全.安全异常: 安全错误。 在 MS.Internal.InternalWebRequest.Send() 在 System.Net.BrowserHttpWebRequest.BeginGetResponseImplementation() 在 System.Net.BrowserHttpWebRequest.InternalBeginGetResponse(AsyncCallback 回调,对象状态)位于 System.Net.AsyncHelper.<>c__DisplayClass4.b__3(Object sendState) --- 内部结束 异常堆栈跟踪 --- at System.Net.AsyncHelper.BeginOnUI(BeginMethod beginMethod,AsyncCallback回调, 对象状态)在 System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback 回调,对象状态)位于 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteSend(IAsyncResult 结果)在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnSend(IAsyncResult 结果)}
关于如何取得进展有什么想法吗?
Im calling a locally hosted wcf service from silverlight and I get the exception below.
Iv created a clientaccesspolicy.xml, which is situated in the route of my host.
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
An error occurred while trying to make
a request to URI
'http://localhost:8005/Service1.svc'.
This could be due to a cross domain
configuration error. Please see the
inner exception for more details. --->{System.Security.SecurityException
---> System.Security.SecurityException:
Security error. at
MS.Internal.InternalWebRequest.Send()
at
System.Net.BrowserHttpWebRequest.BeginGetResponseImplementation()
at
System.Net.BrowserHttpWebRequest.InternalBeginGetResponse(AsyncCallback
callback, Object state) at
System.Net.AsyncHelper.<>c__DisplayClass4.b__3(Object sendState) --- End of inner
exception stack trace --- at
System.Net.AsyncHelper.BeginOnUI(BeginMethod
beginMethod, AsyncCallback callback,
Object state) at
System.Net.BrowserHttpWebRequest.BeginGetResponse(AsyncCallback
callback, Object state) at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteSend(IAsyncResult
result) at
System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.OnSend(IAsyncResult
result)}
Any ideas on how to progress?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
有一些调试技术 此处列出..还有一个有用的帖子..
there are some debugging techniques listed here..one more useful post..
我知道该服务工作正常,因为我将其添加为基本网站的参考并且它有效。 我将尝试使用 Fiddler,尽管存在一个小问题,因为 xaml 控件未嵌入到网页中,但它使用内置的测试页渲染器。
以下是 iv 发现需要检查的一些提示:
添加 clientaccesspolicy.xml,如我的问题所示。
将 crossdomain.xml 添加到主机路由:
确保绑定是 basicHttp,因为这是 silverlight(当前)唯一支持的
服务 该服务需要此属性:
有用的读取:
http://weblogs。 asp.net/tolgakoseoglu/archive/2008/03/18/silverlight-2-0-and-wcf.aspx
http://timheuer.com/blog/archive/2008/06/06/changes-to -accessing-services-in-silverlight-2-beta-2.aspx
http: //silverlight.net/forums/t/19191.aspx
http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx
I know the service is working correctly, because I added it as a reference to a basic website and it worked. I'll try to play with Fiddler, although there is a slight issue as the xaml control is not embedded into a web page, its using the inbuilt testpage renderer.
Here is a few pointers that iv found that need to be checked:
Adding a clientaccesspolicy.xml as a shown my question.
Adding a crossdomain.xml to the host route:
Ensure binding is basicHttp as this is the only one supported by silverlight(currently)
The service needs this attribute:
Useful reads:
http://weblogs.asp.net/tolgakoseoglu/archive/2008/03/18/silverlight-2-0-and-wcf.aspx
http://timheuer.com/blog/archive/2008/06/06/changes-to-accessing-services-in-silverlight-2-beta-2.aspx
http://silverlight.net/forums/t/19191.aspx
http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx
我通过网络广播提供了一些调试技术,试图演示我所写的一些技术:https://www.livemeeting.com/cc/mseventsbmo/view?id=1032386656&role=attend&pw=F3D2F263
Some debugging techniques available via a webcast I did that attempted to demonstrate some of the techniques I wrote about: https://www.livemeeting.com/cc/mseventsbmo/view?id=1032386656&role=attend&pw=F3D2F263
不知道您的问题是否相同,但我刚刚在博客中讲述了本周末尝试通过我的 SL 应用程序与我的控制台托管的 WCF 服务进行跨域发生时遇到的主要痛苦。
http://wallism.wordpress.com/2009/03/01 /silverlight-communication-exception/
简而言之,您必须有一个 crossdomain.xml 并且没有 'headers="*"'
您可以使用“SOAPAction”代替标头的 * (无论哪种方式都可以工作) )
哦,当你让它工作时,你可能想让它更安全一点:-)
祝你好运!
Don't know if your issue is the same but I've just blogged about the major pain I had this weekend trying to get cross-domain happening with my SL app talking to my Console hosted WCF service.
http://wallism.wordpress.com/2009/03/01/silverlight-communication-exception/
In a nutshell though, you must have a crossdomain.xml and don't have 'headers="*"'
Instead of * for headers you can have "SOAPAction" (work's either way)
Oh and when you do get it working you may want to make it a bit more secure :-)
Good luck!
如果您在提供 Silverlight 应用程序的同一位置使用 WCF 服务,则不需要跨域策略。 当从多个实体之间存在关系的客户端返回 LINQ to SQL 数据时,我遇到了类似的错误。
首先确保您的 WCF 服务正常工作。 通过创建一个仅回显其输入的简单 ping 函数来实现此目的。 确保您可以先调用它。 如果这有效,而您的其他函数不起作用,则可以使用函数的参数或返回值。 如果第一个函数也失败,请使用 Fiddler 等工具来查看通过线路发送的数据。 用一个 。 在主机末尾查看来自本地主机的数据。 因此,类似于 http://localhost:1234./default.aspx 并使用相同的 WCF 地址。
If you are using a WCF service at the same location the Silverlight app was served from you don't need a cross domain policy. I have had similar errors when returning LINQ to SQL data from the client where there was a relation between multiple entities.
First make sure you WCF service is working properly. Do this by creating a simple ping function that just echos its input. Make sure you can call this first. If this works and your other function doesn't its something, either with the parameters or return of the function. If the first function also fails use a tool like Fiddler to see what data is send over the wire. Use a . at the end of the host to see the data from localhost. So something like http//localhost:1234./default.aspx and use the same for the WCF address.
我首先使用 Fiddler、FireBug 或类似工具检查网络调用,确保 Silverlight 确实找到了您的客户端访问策略文件。
I'd start by making sure Silverlight is actually finding your client access policy file by inspecting the network calls using Fiddler, FireBug, or a similar tool.
我有同样的问题。 我确实看到 silverlight 客户端应用程序已成功获取 clientaccesspolicy.xml。 我确实通过 firefox 直接请求 clientaccesspolicy.xml 来确保它没有格式错误。 政策是开放的,和上面的一样。
现在奇怪的转折来了。 如果我删除 clientaccesspolicy.xml 并添加 Flash 样式 crossdomain.xml 策略文件,那么它就可以工作。 通过检查网络,我确实看到 clientaccesspolicy.xml 如何首先请求失败,然后 silverlight 又退回到 crossdomain.xml。
所以我确实有一个解决办法,但我更喜欢让 clientaccesspolicy.xml 工作,这样就不会出现额外的不必要的网络往返。
有什么建议么?
i have same problem. I do see that clientaccesspolicy.xml is fetched by silverlight client app successfully. I did ensure clientaccesspolicy.xml is not malformed by requesting it directly via firefox. The policy is wide open, same as the one above.
Now here comes the bizarre twist. If I remove clientaccesspolicy.xml and instead add the Flash style crossdomain.xml policy file then it works. I do see through inspecting the network, how clientaccesspolicy.xml is requested first unsuccessfully and then silverlight falls back to crossdomain.xml.
So I do have a work around, but I prefer making clientaccesspolicy.xml work so that there is no additional unneeded network round trip.
Any suggestions?
我找到了 John Papa 的 Data-Driven Services with Silverlight 2 这本书广泛地讨论这一点。 我也遇到了同样的问题,这本优秀的书解释了这一切。
I found the book, Data-Driven Services with Silverlight 2 by John Papa to go over this extensively. I had the same issues and this excellent book explains it all.
确保 WCF 服务的端点和绑定定义正确。 从同一应用程序调用 WCF 服务不需要跨域策略文件。
Make sure Endpoints and Binding of WCF service are defined correctly. To call WCF service from same application does not need cross domain policy file.
我遇到了类似的问题,删除服务引用并再次添加回来解决了我的问题。
I had a similar problem and removing the service reference and adding it back again solved the problem for me.