{"id":1583,"date":"2009-11-05T22:43:08","date_gmt":"2009-11-05T22:43:08","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2009\/11\/05\/enabling-x-domain-access-to-your-data-services\/"},"modified":"2009-11-05T22:43:08","modified_gmt":"2009-11-05T22:43:08","slug":"enabling-x-domain-access-to-your-data-services","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/enabling-x-domain-access-to-your-data-services\/","title":{"rendered":"Enabling X-Domain access to your Data Services"},"content":{"rendered":"<p>In the Astoria V1.5 CTP2 release, we introduced support for <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2009\/09\/03\/using-the-ado-net-data-services-silverlight-client-in-x-domain-and-out-of-browser-scenarios-i.aspx\">X-Domain and Out Of Browser access to Data Services<\/a> in our Silverlight client library. <\/p>\n<p>This blog post talks about how to enable Cross-Domain access to Data Services from the Silverlight client library. <\/p>\n<h3>I am a Service author, How do I enable X-Domain access to Data Services I host in my applications?<\/h3>\n<p>You would need to deploy a ClientAccessPolicy.xml file to enable X-Domain and Out Of Browser access to Data Services hosted by your applications. <\/p>\n<p>The CAP.xml file should be deployed at the root of the Web Server hosting the Data Services and should not require authentication to access the file.<\/p>\n<h3><b>What is a <\/b><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc197955%28VS.95,lightweight%29.aspx\">ClientAccessPolicy.xml<\/a><b><\/b><b> file? <\/b><\/h3>\n<p>A client access policy file defines the Services that client Silverlight applications can call    <br \/>and the capabilities that these service calls can have.     <br \/>Here is a sample client access policy.xml file : <\/p>\n<p><font face=\"Courier New\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;     <br \/><\/font><font face=\"Courier New\">&lt;access-policy&gt;     <br \/><\/font><font face=\"Courier New\">&#160; &lt;cross-domain-access&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160; &lt;policy&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; &lt;allow-from http-request-headers=&quot;*&quot;&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;domain uri=&quot;http:\/\/ui.norhtwind.com&quot;\/&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; &lt;\/allow-from&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; &lt;grant-to&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;resource path=&quot;\/Northwind.svc&quot; include-subpaths=&quot;true&quot;\/&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; &lt;\/grant-to&gt;     <br \/><\/font><font face=\"Courier New\">&#160;&#160;&#160; &lt;\/policy&gt;     <br \/><\/font><font face=\"Courier New\">&#160; &lt;\/cross-domain-access&gt;     <br \/><\/font><font face=\"Courier New\">&lt;\/access-policy&gt;<\/font><\/p>\n<h3>Anatomy of&#160; a ClientAccessPolicy.xml file:<\/h3>\n<p>The CAP.xml file contains a lot of sections to allow fine tuning of client access.    <br \/>For a Data Service author, the following are relevant sections of the file:    <\/p>\n<p>1. <b>&lt;allow-from&gt; <\/b><\/p>\n<p>Defines all the domains that are affected by this policy.    <\/p>\n<p>Defines the sites that are allowed to access resources in a certain policy.     <\/p>\n<p>By using the allow-from element for a particular policy, you implicitly deny access for all non-listed domains. <\/p>\n<p>If allow-from is empty, then the policy file grants access to no sites.    <\/p>\n<p>The \u201c<b>http-request-headers<\/b>\u201d&#160; attribute of this node specifies the HTTP Request headers that client Service calls are allowed to pass to the Service. <\/p>\n<p>For a Data Services Silverlight client application, the following headers are required <\/p>\n<ol>\n<ol>\n<li>X-Http-Method <\/li>\n<li>DataServiceVersion&#160; <\/li>\n<li>Accept <\/li>\n<li>Content-Type <\/li>\n<li>Location <\/li>\n<li>MimeType&#160; <\/li>\n<li>MaxDataServiceVersion <\/li>\n<\/ol>\n<\/ol>\n<p>2. &lt;<b>allow-from&gt;&lt;domain\/&gt;&lt;\/allow-from&gt;<\/b><\/p>\n<p>The <b>\u201curi\u201d<\/b> attribute of the \u201c<b>domain<\/b>\u201d node specifies the domain in which the client accessing the Service has to be hosted     <br \/>to be able to call the Service.<\/p>\n<p>3. <b>&lt;grant-to&gt; <\/b><\/p>\n<p>The \u201c&lt;grant-to&gt;\u201d node specifies the Services which are allowed to be accessed by clients. <\/p>\n<p>4. <b>&lt;grant-to&gt;&lt;resource\/&gt;&lt;\/grant-to&gt; <\/b><\/p>\n<p>Each service , access to which is governed by the CAP.xml file, is represented by a <b>&lt;resource&gt; <\/b>node in the <b>&lt;grant-to&gt;<\/b> section of the CAP.xml file .     <\/p>\n<p>The <b>&lt;resource&gt; <\/b>node contains two important attributes. <\/p>\n<ol>\n<ol>\n<li><b>path <\/b>: this attribute is the relative path of the Data Service <\/li>\n<li><strong>include-subpaths<\/strong>&#160; : this attribute specifies if paths based off of the resource path are allowed. This value should be set to true for a Data Service. <\/li>\n<\/ol>\n<\/ol>\n<h3>Additional references:<\/h3>\n<ol>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc645032%28VS.95%29.aspx\">Clientaccesspolicy.xml file Schema<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc197955%28VS.95%29.aspx\">Making a Service Available Across Domain Boundaries<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In the Astoria V1.5 CTP2 release, we introduced support for X-Domain and Out Of Browser access to Data Services in our Silverlight client library. This blog post talks about how to enable Cross-Domain access to Data Services from the Silverlight client library. I am a Service author, How do I enable X-Domain access to Data [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[6,37,67,92],"class_list":["post-1583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-ado-net-data-services","tag-how-to","tag-silverlight","tag-x-domain"],"acf":[],"blog_post_summary":"<p>In the Astoria V1.5 CTP2 release, we introduced support for X-Domain and Out Of Browser access to Data Services in our Silverlight client library. This blog post talks about how to enable Cross-Domain access to Data Services from the Silverlight client library. I am a Service author, How do I enable X-Domain access to Data [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=1583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=1583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=1583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=1583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}