WCF Service Call from Silverlight

I call the locally hosted wcf service from silverlight and I get an exception below.

Iv created clientaccesspolicy.xml, which is in the path 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 the URI ' http: // localhost: 8005 / Service1.svc '. This may be due to a cross-domain configuration error. See internal exception for more details. --->

{System.Security.SecurityException ---> System.Security.SecurityException: Security Error. in MS.Internal.InternalWebRequest.Send () in System.Net.BrowserHttpWebRequest.BeginGetResponseImplementation () in System.Net.BrowserHttpWebRequest.InternalBeginGetResponse (AsyncCallback callback, object state) in System.Net.Asyn <> c__DisplayClass4.b__3 (Object sendState) --- The end of the internal trace of the exception stack - when System.Net.AsyncHelper.BeginOnUI (BeginMethod beginMethod, callback AsyncCallback, Object state) when System.Net.BrowserHttpWebRequest.BeginGetResallback ( state of the object) in System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteSend (IAsyncResult result) in System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.NestHannel.nesthannels.nesthannels.nesthannels.nesthannels.nesthannels.nest

Any ideas on how to move forward?

+4
source share
10 answers

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

+7
source

I know that the service works correctly because I added it as a link to the base website, and it worked. I will try to play with Fiddler, although there is a slight problem, because the xaml control is not embedded in the web page using the built-in test page visualizer.

Here are a few pointers that iv found to check:

Adding clientaccesspolicy.xml as my question shown.

Adding crossdomain.xml to the hosting:

 <!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> 

Provide a basicHttp binding as this is the only silverlight supported (currently)

The service needs this attribute:

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

Useful to read: 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

+2
source

Some of the debugging methods available through the webcast I made tried to demonstrate some of the methods that I wrote about: https://www.livemeeting.com/cc/mseventsbmo/view?id=1032386656&role=attend&pw=F3D2F263

+1
source

I don’t know if your problem was the same, but I just wrote about the big pain I was experiencing this weekend to get a cross-domain incident with my SL application associated with my Console WCF service.

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

In a nutshell, you should have crossdomain.xml and not have "headers =" * "'

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

Instead of * for headings, you can have "SOAPAction" (work anyway)

Oh, and when you earn it, you can make it safer :-)

Good luck

+1
source

To begin with, Silverlight will indeed find your client access policy file by checking network calls using Fiddler, FireBug, or a similar tool.

0
source

If you use the WCF service in the same place, the Silverlight application has been served, you do not need a cross-domain policy. I had similar errors when returning LINQ to SQL data from a client, where there was a connection between several objects.

First, make sure the WCF service is working properly. Do this by creating a simple ping function that simply rephrases its input. Make sure you can call first. If this works, and your other function does not matter, either with parameters or with a function return. If the first function also does not work, use a tool like Fiddler to find out what data is being sent over the wire. Use. at the end of the host to see data from localhost. So, something like http // localhost: 1234./default.aspx and use the same for the WCF address.

0
source

I have the same problem. I see that clientaccesspolicy.xml is loading successfully with the silverlight client application. I guaranteed that clientaccesspolicy.xml is not distorted by requesting it directly through firefox. The policy is widely disclosed, the same as above.

Now here's a bizarre twist. If I remove clientaccesspolicy.xml and add a Flash-style crossdomain.xml policy file instead, it will work. I look at the network information as the clientaccesspolicy.xml request fails first and then silverlight returns to crossdomain.xml.

So, I have a job, but I prefer to make clientaccesspolicy.xml work so that there is no unnecessary unnecessary network both ways.

Any suggestions?

0
source

I found a book, Data-Driven Services with Silverlight 2 from John Papa, to understand this in detail. I had the same problems and this excellent book explains all this.

0
source

Verify that the endpoints and WCF service bindings are defined correctly. To call the WCF service from the same application, the cross-domain policy file is not required.

0
source

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

0
source

Source: https://habr.com/ru/post/1277080/


All Articles