Silverlight client access policy problem - silverlight

I have a wcf webservice which I call from my silverlight application, using https, and it works fine without any problems. Now I got to add a new reference to an old service (soap/asmx) from the silverlight client which went ok. Then when I tried to access the service, I get the following errors:
An error occurred while trying to make a request to URI 'http://localhost/OldService.asmx'. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services....
Note: that the asmx service is using http instead of https.
My clientaccesspolicy file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

I think you need to use only Silverlight enabled service.
Silverlight works only with *.svc services, so you can not use *.asmx service in Silverlight project.

I have solved it actually, I just made them all https.

Related

clientaccesspolicy.xml not being called

I'm currently trying to put a silverlight web part in place onto our intranet.
As I do not have access to the ClientBin folder of the SharePoint 2010 box, I created a simple list and a content editor web part to host my app.
The silverlight app runs correctly from my local machine (xxxx.int.mydomain.com) but not from the SharePoint site (siteTest.int.mydomain.com).
This app is calling a web service hosted at: http://xxx.mydomain.com/yyy/ws.asmx
I get the following error message:
An error occurred while trying to make a request to URI
'http://xxx.imd.ch/yyy/ws.asmx'.
This could be due to attempting to access a service in a cross-domain
way without a proper cross-domain policy in place, or a policy that is
unsuitable for SOAP services. You may need to contact the owner of the
service to publish a cross-domain policy file and to ensure it allows
SOAP-related HTTP headers to be sent. This error may also be caused by
using internal types in the web service proxy without using the
InternalsVisibleToAttribute attribute. Please see the inner exception
for more details. System.
The clientaccesspolicy.xml file reads:
<?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>
Calling the clientaccesspolicy from the browser is working fine:
<?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>
When I use fiddler to try to understand what's happening, I cannot see any request to any xml file.
Could it be related to any specific thing with SharePoint 2010. How could I debug it further?

cross-domain policy file error

I am using WCF service (Not RIA) and silverlight I am getting the following error :
An error occurred while trying to make
a request to URI
'http://localhost:8732/'. This could
be due to attempting to access a
service in a cross-domain way without
a proper cross-domain policy in place,
or a policy that is unsuitable for
SOAP services. You may need to contact
the owner of the service to publish a
cross-domain policy file and to ensure
it allows SOAP-related HTTP headers to
be sent. This error may also be caused
by using internal types in the web
service proxy without using the
InternalsVisibleToAttribute attribute.
Please see the inner exception for
more details.
I have tried adding the following to my the clientaccesspolicy.xml file and the crossdomain.xml to the root of my web project. they look like this...
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="http://*"/>
<domain uri="https://*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
crossdomain.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Any ideas why I am getting this?
Thanks in advance.
If you can't install fiddler, can you download and use TcpTrace? http://www.pocketsoap.com/tcptrace/
The clientaccesspolicy.xml needs to be placed at the root of the website hosting your WCF service and not at the root of your web project.
I ran into this problem with a SOAP WCF service as soon as I moved by WCF service into a separate web app from my Silverlight web app project. Even with my clientaccesspolicy.xml in the WCF web app's root, I was still getting this error. The fastest solution for me was to change my WCF service from SOAP to REST, and then finally Silverlight recognized the clientaccesspolicy.xml and the requests started working again.

Serving clientaccesspolicy.xml through WCF Rest service, while hosting on IIS

I am building a simple HTTP file server.
I have an asp.net web application that exposes a WCF service (FileService.svc).
The service contract is:
[OperationContract]
[WebGet(UriTemplate = "/*")]
Stream HandleFileRequest();
The service implementation is quite straightforward and basically I use :
WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri
To get the path of the file to return (A little parsing is required to extract it).
So for instance, when hosting the app locally on IIS , I can request a file from :
http://localhost:65000/FileService.svc/someFolder1/someFolder2/someFile1.jpg
The problems starts when this request is made from inside a silverlight app. Silverlight searches the clientaccesspolicy file in http://localhost:65000/clientaccesspolicy.xml
The problem is that now, this request won't reach the service because FileService.svc is ommited from the url.
(I want all the file requests to be handled by the WCF service in HandleFileRequest(), and not any other mechanism.)
One solution I can think of is to use the URL Rewrite module of IIS 7.
Is this the right way to do this, or there simpler solution to this ?
The clientaccesspolicy.xml used by Silverlight has to be on the domain root - in your example that would mean http://localhost:65000/clientaccesspolicy.xml. The policy file is unique per domain, not per service. You can, however, set different policies for different services by adding one element for each service in the clientaccesspolicy.xml file, as shown in the example below.
<?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="/FileService.svc/" include-subpaths="true"/>
</grant-to>
</policy>
<policy>
<allow-from http-request-headers="*">
<domain uri="http://some.other.domain"/>
</allow-from>
<grant-to>
<resource path="/AnotherService/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

cross-domain problem on silverlight and wCF access

I wrote WCF service and i also wrote ( in the same solution ) silverlight client.
I trying to access to the WCF service from the silverlight client - and i get cross-domain exception.
this is happening only when i run the system on the server machine ( thru IIS 7.5 )
I tried to run the same system ( the wcf server & silverlight client ) on my local machine
and its does not happened.
The exception:
An error occurred while trying to make a request to URI ‘http://localhost:4522/MyService’. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent. Please see the inner exception for more details.
I saw on the web that i need to add something like ICrossDomainService - but i don't know where i need to define them on my project ( on the silverlight project ? on the WCF server project ? )
Someone can help me please ?
Thanks.
I think you will need to create a client access policy file in the root folder of the web site.
This described here: http://msdn.microsoft.com/en-us/library/cc645032(v=vs.95).aspx
A policy file looks like this, and you will need to tailor it according to your cross-domain requirements. This example was taken from MSDN and probably can't be used without being changed.
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<!--Enables Silverlight 3 all methods functionality-->
<policy>
<allow-from http-methods="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/api" include-subpaths="true"/>
</grant-to>
</policy>
<!--Enables Silverlight 2 clients to continue to work normally -->
<policy>
<allow-from >
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/api" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
I'm not too familiar with the schema, but I'd hit MSDN again for that. Something like this might be closer:
</cross-domain-access>
<policy>
<allow-from>
<domain uri="*"/>
</allow-from>
<grant-to>
<resource/>
</grant-to>
</policy>
</cross-domain-access>
PLEASE check MSDN to make sure you don't open a security hole!

Still having issues with my cross domain policy in Silverlight 3.0

So I'm using both xml files listed below with no luck. They both exist in the root of my IIS hosted web service on a different web server (behind the firewall). The web service is a simple POX like service that returns a JSON string.
Also I'm trying to get access to this service from a cassini run project on my local machine (to test it out). I can view the JSON from a browser but get a security error in silverlight when I try to do an HTTP GET using the same uri (4004 is the error code shown)
Anything simple that I missed here?
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>
crossdomain.xml
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only" />
<allow-access-from domain="*" secure="true" />
</cross-domain-policy>
Are you using a tool like fiddler to see what address the request for the cross domain policy file is pointed at? That's usually my first check; if the policy file isn't being found I'll know where it's supposed to be and if it is then I usually need to look elsewhere.
Your clientaccesspolicy.xml is identical to my reference one. Should be no problems there.
If you get a 404 response code, the only reason can be that the server can not find the resource you are looking for. So are you absolutely sure you are using the correct url?

Resources