从 Silverlight 调用 WCF 服务

发布于 2024-07-06 03:29:40 字数 1655 浏览 8 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

才能让你更想念 2024-07-13 03:29:40

有一些调试技术 此处列出..还有一个有用的帖子..

there are some debugging techniques listed here..one more useful post..

花心好男孩 2024-07-13 03:29:40

我知道该服务工作正常,因为我将其添加为基本网站的参考并且它有效。 我将尝试使用 Fiddler,尽管存在一个小问题,因为 xaml 控件未嵌入到网页中,但它使用内置的测试页渲染器。

以下是 iv 发现需要检查的一些提示:

添加 clientaccesspolicy.xml,如我的问题所示。

将 crossdomain.xml 添加到主机路由:

<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

确保绑定是 basicHttp,因为这是 silverlight(当前)唯一支持的

服务 该服务需要此属性:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

有用的读取:
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:

<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

Ensure binding is basicHttp as this is the only one supported by silverlight(currently)

The service needs this attribute:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

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

花开浅夏 2024-07-13 03:29:40

我通过网络广播提供了一些调试技术,试图演示我所写的一些技术: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

甜心小果奶 2024-07-13 03:29:40

不知道您的问题是否相同,但我刚刚在博客中讲述了本周末尝试通过我的 SL 应用程序与我的控制台托管的 WCF 服务进行跨域发生时遇到的主要痛苦。

http://wallism.wordpress.com/2009/03/01 /silverlight-communication-exception/

简而言之,您必须有一个 crossdomain.xml 并且没有 'headers="*"'

Bad:
    <allow-access-from domain=""*"" headers="*" />

Good:
    <allow-access-from domain=""*"" />
    <allow-http-request-headers-from domain=""*"" 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="*"'

Bad:
    <allow-access-from domain=""*"" headers="*" />

Good:
    <allow-access-from domain=""*"" />
    <allow-http-request-headers-from domain=""*"" 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!

柠檬色的秋千 2024-07-13 03:29:40

如果您在提供 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.

半暖夏伤 2024-07-13 03:29:40

我首先使用 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.

旧街凉风 2024-07-13 03:29:40

我有同样的问题。 我确实看到 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?

酷遇一生 2024-07-13 03:29:40

我找到了 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.

夜还是长夜 2024-07-13 03:29:40

确保 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.

小耗子 2024-07-13 03:29:40

我遇到了类似的问题,删除服务引用并再次添加回来解决了我的问题。

I had a similar problem and removing the service reference and adding it back again solved the problem for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文