Silverlight Cross-Domain Scripting Application

I'm having issues with cross-domain application hosting with Silverlight.

I have an application hosted in a different domain and including the following HTML code on a page:

<script type="text/javascript"> function succ( sender, args ) { console.log("SUCCESS"); console.log(sender); console.log(args); } function err( sender, args ) { console.log("FAILURE"); console.log(sender); console.log(args); } </script> <object width="400" height="20" id="app" type="application/x-silverlight-2" data="data:application/x-silverlight-2,"> <param name="minruntimeversion" value="4.0.41108.0"/> <param name="autoupgrade" value="false"/> <param name="onerror" value="err"/> <param name="onload" value="succ"/> <param name="enablehtmlaccess" value="true"/> <param name="source" value="http://example.com/app.xap"/> </object> 

But if the app.xap application app.xap hosted in another domain from this HTML, the onLoad succ function is called without arguments, so it writes the following lines:

 SUCCESS undefined undefined 

If I am hosted in the same domain, it writes the correct lines:

 SUCCESS UserControl {} undefined 

So, in the first case, I could not get the annotated methods [ScriptableMember] from javascript, because I have no link to the application.

In the AppManifest.xml file AppManifest.xml I included the attribute required by the HtmlPage.RegisterScriptableObject method, like this:

 <Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ExternalCallersFromCrossDomain="ScriptableOnly" > <Deployment.Parts> </Deployment.Parts> </Deployment> 

The xap file xap transferred using application/x-silverlight-app Content-Type , so this is not a problem either.

What am I missing?

Thanks!

+4
source share
2 answers

Suppose you register an external object named Thingy.

You must have access to it through the Content property of the html object element. Put the id="mySL" tag in the object tag. Now try this code: -

 function succ( sender, args ) { console.log("SUCCESS"); console.log(document.getElementById("mySL").Content.Thingy); console.log(args); } 

Just remember to register โ€œThingyโ€ at an early stage of your code, as in the constructor of the class that you use as the root image.

+2
source

The same problem is solved as a starter theme described in his comment.

I had to put my whole script in my root visual class

0
source

All Articles