{"id":1333,"date":"2008-09-29T12:07:51","date_gmt":"2008-09-29T12:07:51","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/cesardelatorre\/2008\/09\/29\/using-silverlight-2-0-clientaccesspolicy-xml-vs-crossdomain-xml-for-web-service-cross-domain-access\/"},"modified":"2008-09-29T12:07:51","modified_gmt":"2008-09-29T12:07:51","slug":"using-silverlight-2-0-clientaccesspolicy-xml-vs-crossdomain-xml-for-web-service-cross-domain-access","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/using-silverlight-2-0-clientaccesspolicy-xml-vs-crossdomain-xml-for-web-service-cross-domain-access\/","title":{"rendered":"Using Silverlight 2.0 clientaccesspolicy.xml vs. crossdomain.xml for Web-Service cross-domain access"},"content":{"rendered":"<\/p>\n<p>To enable a Silverlight control to access a web service (like a WCF Service) in another domain, the service must explicitly allow cross-domain access. Doing so, a service states that the operations it exposes can safely be invoked by a Silverlight control, without potentially damaging consequences to the data the service stores.<\/p>\n<p>Silverlight supports two different mechanisms for services to opt-in to cross-domain access:     <br \/>&#8226;&#160;&#160;&#160; Place a clientaccesspolicy.xml file at the root of the domain where the service is hosted to configure the service to allow cross-domain-access.     <br \/>&#8226;&#160;&#160;&#160; Place a valid crossdomain.xml file at the root of the domain where the service is hosted. Silverlight supports a subset of the crossdomain.xml schema. This file format is supported as well by ADOBE FLASH (originally by them).<\/p>\n<p>&#160;<\/p>\n<p>The question many developers could ask is, ok, <strong>which format\/file do I use?.<\/strong><\/p>\n<p>Well, even though crossdomain.xml is supported by ADOBE FLASH, as well, there is a limitation in current SL20 Beta2 version: If you use crossdomain.xml, the file must mark the entire domain public. I mean, the file must be configured to allow access to the web service from any other domain, or it is not recognized by Silverlight&#8230; (Keep in mind that this is a Silverlight&#8217;s limitation, probably by design).<\/p>\n<p>You should configure crossdomain.xml like that:<\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"894\" border=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"890\">\n<pre>&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;!DOCTYPE cross-domain-policy SYSTEM &quot;http:\/\/www.macromedia.com\/xml\/dtds\/cross-domain-policy.dtd&quot;&gt;\n&lt;cross-domain-policy&gt;\n  &lt;allow-http-request-headers-from <strong>domain=&quot;*&quot;<\/strong> headers=&quot;*&quot;\/&gt;\n&lt;\/cross-domain-policy&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>So, because of that, I&#8217;d always use clientaccesspolicy.xml which allows me to specify all domains OR just specific domains, like the following:<\/strong><\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"892\" border=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"888\">\n<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;access-policy&gt;\n  &lt;cross-domain-access&gt;\n    &lt;policy&gt;\n      &lt;allow-from http-request-headers=&quot;*&quot;&gt;\n        <strong>&lt;domain uri=&quot;http:\/\/contoso.com&quot;\/&gt;<\/strong>\n      &lt;\/allow-from&gt;\n      &lt;grant-to&gt;\n        &lt;resource path=&quot;\/&quot; include-subpaths=&quot;true&quot;\/&gt;\n      &lt;\/grant-to&gt;\n    &lt;\/policy&gt;\n  &lt;\/cross-domain-access&gt;\n&lt;\/access-policy&gt;<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>btw, you could always use both files within your Web-Service, so then, Silverlight client apps would check first clientaccesspolicy.xml and apply specific restrictions based on specific domains, no matter what crossdomain.xml says.<\/p>\n<p>Of course, crossdomain.xml will be used by FLASH client apps.<\/p>\n<p><strong>So this is the answer!: &quot;Use both files (if you want Flash support for your web-service), but apply specific restrictions into clientaccesspolicy.xml&quot; for Silverlight client apps&quot;.<\/strong><\/p>\n<p>Here you can see the Silverlight&#8217;s Cross Domain Policy Flow:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_2.png\"><img decoding=\"async\" style=\"border-right: 0px;border-top: 0px;border-left: 0px;border-bottom: 0px\" height=\"533\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/32\/2019\/03\/image_thumb.png\" width=\"796\" border=\"0\" \/><\/a> <\/p>\n<p>&#160;<\/p>\n<p>Remember!, Always save the clientaccesspolicy.xml&#160; or the crossdomain.xml file into the root of the domain\/web-site where the service is hosted. If, for example, the service is hosted in <a href=\"http:\/\/www.mycompany.com\">http:\/\/www.mycompany.com<\/a> then the file must be located at <a href=\"http:\/\/www.mycompany.com\/crossdomain.xml\">http:\/\/www.mycompany.com\/crossdomain.xml<\/a>. <u>You cannot put it within your App&#8217;s Virtual Directory<\/u>, like <a href=\"http:\/\/www.mycompany.com\/myapp\/crossdomain.xml\">http:\/\/www.mycompany.com\/myapp\/crossdomain.xml<\/a>. This is wrong and it won&#8217;t work<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To enable a Silverlight control to access a web service (like a WCF Service) in another domain, the service must explicitly allow cross-domain access. Doing so, a service states that the operations it exposes can safely be invoked by a Silverlight control, without potentially damaging consequences to the data the service stores. Silverlight supports two [&hellip;]<\/p>\n","protected":false},"author":362,"featured_media":12806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cesardelatorre"],"acf":[],"blog_post_summary":"<p>To enable a Silverlight control to access a web service (like a WCF Service) in another domain, the service must explicitly allow cross-domain access. Doing so, a service states that the operations it exposes can safely be invoked by a Silverlight control, without potentially damaging consequences to the data the service stores. Silverlight supports two [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media\/12806"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}