Skip to main content
Home Forums Silverlight Programming Programming with .NET - General cross domain issue
20 replies. Latest Post by rucsi on September 4, 2008.
(1)
Ryan7979
Member
14 points
22 Posts
07-23-2008 6:06 AM |
hey all:
I used SLB2 and got a problem about cross domain , my setting as below
1.create a web service (.asmx) on server A.
2.xap file is on server A
3.create clientaccesspolicy.xml and crossdomain.xml file to the root of server A
4.clientaccesspolicy.xml configuration as follow
<?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>
5.crossdomain.xml configuration as follow
<?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>
=================================================
so far , I can use silverlight call web service successfully on server A , my html source tag as below
<param name="source" value="ClientBin/mySilverlight.xap"/>
but it call web service fail when I move html file to server B and modify source tag to
<param name="source" value="http://serverA-Domain/ClientBin/mySilverlight.xap"/>
could anyone knows what's wrong with that and how to fix it?
dharmesh...
83 points
30 Posts
07-23-2008 6:30 AM |
when some one request html page, that request comes to ur server b not server A, and u have that policy file on server A, u r calling server A from server B
rajesh s...
Contributor
2314 points
505 Posts
07-23-2008 6:31 AM |
I think you need to add Crossdoamin.xml file in server B too.
There are lot of cross domain issues links in this forum have you chked those
http://silverlight.net/forums/p/10513/33583.aspx
http://silverlight.net/forums/p/11496/36719.aspx
http://silverlight.net/forums/p/10944/34765.aspx
http://silverlight.net/forums/p/11199/35697.aspx
07-23-2008 7:56 PM |
thanks Dharmesh and Rajesh
actually I don't know where server B is, because I just build xap file and web service in server A and let anyone who need this service to use,
they can copy <object> .... </object> tag to their web site no matter where it is
so pls let me know how could I fix this problem ?
sladapter
All-Star
17445 points
3,173 Posts
07-23-2008 9:05 PM |
Is there a particular reason you moved your HTML file without the .Xap file? Usually people deploy the HTML with .Xap file. But the service can run from any server.
But I guess if you use absolute URL for your Service call in the ClientConfig, this should not matter. Unless you used relative url in the Service call. what is the URL for your service in your ClientConfig (if you did not hard code it in the code)?
07-23-2008 9:22 PM |
thanks sladapter
yes, I'm using absolute URL for my service call in the clientconfig , my cilentconfig as below
<configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="SilverlightServiceSoap" maxBufferSize="65536" maxReceivedMessageSize="65536"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://www.serverA.com/WebService/Silverlight.asmx" binding="basicHttpBinding" bindingConfiguration="SilverlightServiceSoap" contract="Billboard.ws.SilverlightServiceSoap" name="SilverlightServiceSoap" /> </client> </system.serviceModel></configuration>
I moved HTML file to Server B just want to simulate situation that someone copy HTML <object>...</object> tag and paste on their web page ( like server B), I'd like to share my silverlight object to anyone who need this service.
07-23-2008 10:03 PM |
btw , I read this article from http://timheuer.com/blog/archive/2008/04/09/silverlight-cannot-access-web-service.aspx
and also make a test like that , than I got this as below
HTML in server A
I can see silverlight call silverlight.asmx successfully and get status is 200
HTML in server B
I don't get any response about call silverlight.asmx , even 404 error
07-23-2008 10:46 PM |
I'll try to do some test on this tomorrow.
You can do the test too. You can make two web sites on your machine. One host your html page. One host the xap file just like you have Xap file on another server. Leave the Service on server B. Then you can try to debug. I guess you have to use Attach to Process option to debug your Silverlight project. Just run your html page on the browser (IE), then attach to the IE see what you get.
07-23-2008 11:22 PM |
I did the test, there's no exception rise when it call web service , after that it didn't into sub servicecomplete (btw, I use vb to develop)
I think it still block from server where the service is.
anyway , I'll expect ur response.
07-24-2008 12:33 AM |
One option is there to use web service :):Create one aspx page and call the web service from that page, in that case u have to copy html and aspx on the new server, thats it.
07-24-2008 1:12 AM |
thanks Dharmesh
acturally web service works normally and there're many other .aspx page call it successfully.
just only silverlight in different server from service.
07-24-2008 1:38 AM |
Actually i mean to say something different.we have to use a third party web service in our silverlight application, but policy file is not there where it hosted. so, we r not able to call it directly from our silverlight app.so to over come this problem, 1) we create one aspx page from where we called this web service. 2) used web client for calling the web service that returns some data. with the use of streamreader converted in string and use response.write to return that data to calling page. 3) from silverlight app. (xaml.cs) - call is made to this page which returns the data.Its not the solution, what u actually looking for.
07-24-2008 3:50 AM |
sorry I misunderstand and maybe I described too crude.I thank ur method could be work.
but I still want to know is there another way to solute this ?
because this project is built by SL2B1 and work perfectly until I update to SL2B2
07-24-2008 12:22 PM |
Hi, I tested your case. Here is what I found:
3 Web Sites on one machine.
Site1: Web Service Site: http://ServerA/WCFService/Test.svc
Site2: Silverlight Site, only to provide Xap file. http://ServerA/SilverlightWeb/ClientBin/MyTest.xap
Site3: Web site to host TestPage.html . http://ServerA/TestWeb/TestPage.html.
Case 1:
Sivlerlight object tag in TestPage.html
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%"> <param name="source" value="http://ServerA/SilverlightWeb/ClientBin/MyTest.xap"/>
..
</object>
Type the following URL in the browser: http://ServerA/TestWeb/TestPage.html. Page load correctly. Click Test button to connect to the service. Service call completed without problem.
Type the following URL in the browser: http://localhost/ServerA/TestWeb/TestPage.html. Page load correctly. Click Test button to connect to the service. No connection is made.
Case 2:
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%"> <param name="source" value="http://localhost/SilverlightWeb/ClientBin/MyTest.xap"/>
Type the following URL in the browser: http://ServerA/TestWeb/TestPage.html. Page load correctly. Click Test button to connect to the service. No connection is made.
Type the following URL in the browser: http://localhost/ServerA/TestWeb/TestPage.html. Page load correctly. Click Test button to connect to the service. Service call completed without problem.
Move the Service to ServerB. Did the same test. Same result.
Summary:
If the Page url and Xap url are from the same domain. The service call has no problem. (The service can be on different domain, as long as crossdomain policy is set).
If the Page url and Xap url are from different domains (http://localhost and http://ServerA are considered cross-domain, even they are the same thing here). Then service call would fail.
I guess this is some kind of security measure. They provent you to access other people's application to access 3rd party's service.
I don't know if the request should be considered come from domainA or domainB if the Page and Xap are from different domains. If Service allow domainA access, not domainB access. Should service allow you to access if you are on DemainB, but load the Xap from domain A?
07-24-2008 8:32 PM |
thanks sladapter, I got the same result.
That's what I really want to know , I can understand that's some kind of scurity measure to provent someone to access other people's application to access 3rd party's service, but what if I really want to share this service ?
here's a flash sample from Picasa Albums , you can embed album slideshow into your page only if you copy this HTML as below and paste into your web page.
<embed type="application/x-shockwave-flash" src="http://picasaweb.google.com/s/c/bin/slideshow.swf" width="288" height="192" flashvars="host=picasaweb.google.com&RGB=0x000000&feed=http%3A%2F%2Fpicasaweb.google.com3Dphoto%26alt%3Drss" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
I guest in this .swf file , it call some service to connect album database and get photo url return ,
Could Silverlight work like that ? I guest it could but you have to do some configure and I really want to know how.
08-26-2008 12:07 PM |
Ryan7979,I don't know if you already have this thing figured out or not. Today I was reading beta2 breaking changes again and come across "AllowInboundCallsFromXDomain" changes. Then I thought about this thread. I don't know if this could solve your problem or not (I have not tried it), but sounds like what you might want to try:You can try to set ExternalCallersFromCrossDomain=FullAccess in the <Deployment /> Tag in your AppManifest.xaml file see if it works.
08-26-2008 10:22 PM |
thanks sladapter , it really work !
I deeply appreciated your help and answered my question patiently. thanks a lot !
08-26-2008 11:07 PM |
Great to hear that really works!
rucsi
7 points
5 Posts
09-03-2008 4:26 AM |
Hi!
I'm having a strange problem, i hope someone can help me. My project should call for the clientaccesspolicy, but it does not. I don't know what could go wrong. On another computer it works fine, but on this when it should call for the policy file, it's just simply don't, at least SL sends no request for the file. It looks like it thinks that it's not a cross-domain, but it is. Maybe something is wrong with my IIS, i don't know, and have no idea. The project is fine, couse as i said it works fine for others.
It network calls need to be like this, but the most important one is missing from my list.
Thanks
09-03-2008 9:10 PM |
Hi rucsi
What's your silverlight version ? clientaccesspolicy file in beta2 is different from beta1
09-04-2008 3:15 AM |
Hi
I'm using beta2. My policy file is correct, for the version. I've solved it. My service was running on localhost, and the SL thought that it is not a cross domain, but it was.