WCF Silverlight crossdomain problem - silverlight

I have several WCF services.
When I check them on the server (example: ServiceTest.svc?wsdl), than I see an xml file with info about the wcf service. So the services works fine.
I have a Silverlight application on a different server.
I get the 'famous' crossdomain error.
When I place a clientaccesspolicy.xml in the directory with the WCF services, the problem remains.
Is it possible that with shared hosting, the security isn't high/low enough?
thanks,
Filip

The XML file must be placed in the root of the domain. Usually you have to put them into the inetpub/wwwroot folder, instead of into the folder with the WCF services.
Depending on how your provider implemented the shared hosting, I'm afraid you'll have to ask them to support cross domain access and put the XML files into the root.
I am not sure but I think it also could work to register your own domain that points to the folder you want to use as root, and put the XML files there. The clients must then use the server URLs with your registered domain of course.

One of the best tools for issues like this is Fiddler(or some other web debugging proxy). Looking at the network calls, you can see the address where the browser is looking for the clientaccesspolicy.xml file and then make sure you drop the file at that location. If you're not seeing this call or you're seeing it and the file is already there, you can move on to other issues (a bug in the webservice or the calling code).

Related

Problem uploading service for Silverlight SQL connection

I've found a very small sample showing Silverlight SQL connection (http://www.codeproject.com/KB/silverlight/CntDbSlght.aspx), I've tested it and it works fine on local system, also I've changed its connection string so that it shows data from my remote database, but when I upload files to my host, I cannot see any SQL data, it seems that something is broken, how should I configure my web.config?
What are CrossDomain.XML and ClientAccessPolicy.XML files? should I upload them? If so, where should they be? How should I bind my service? what am I doing wrong? I click on VS2010 publish (in build menu) and select file system, then I upload all files existing in this folder, I use C#.
If you are trying to access an external Silverlight web service from your local dev environment you certainly need a ClientAccessPolicy.XML file on the website. This tells the site services where requests can come from (normally only from the same site the SL app was run from).
Your ClientAccessPolicy.XML file needs to go into the actual root of your website i.e. 'mydomain.com/ClientAccessPolicy.XML.
*Note: You do not also need a CrossDomain.XML if you have ClientAccessPolicy (which is the SL specific one). CrossDomain.xml is an older flash compatibility file that sometimes exists on sites.

How to host silverlight on S3

I'm trying to host the xap file of my silverlight application on s3.
I'm using RIA services and a wcf service, which are hosted on my side.
So far I haven't been able to get this to work, as the loading animation will play but then the application itself won't load.
What kind of configuration do I need to make this work?
Since that would be a cross-domain call you need a crossdomain.xml on your WCF service. Have you looked at the traffic in Fiddler to see what response you are getting from the server?
Another thing you might run into is that the correct mime types might not be registered on the S3 server. Look here how to fix that.
At the end of the day this wound up being a combination of things:
Both previous answers by #Andy May and #Erno were correct. The mime type needed to be application/x-silverlight-app and the proper crossdomain.xml file had to be present.
Also, the DomainContext for all of my RIA classes had to specify the URI, as by default the pointed to the xap file's host, which was s3.
After these changes were made everything seemed to work just fine.

File Upload Cross Domain

The scenario I am trying to create is to have my Silverlight Website on one domain and my file server (for media files) on a different server. I want to allow my users to upload files to the file server from the website.
The problem is I am getting a generic "Security error." reported back in the inner exception message in my code. The main exception message is blank.
I have set all access right to the physical folders (Windows Server 2008). I have created wide-open clientaccesspolicy.xml and crossdomain.xml files.
I am using an .ashx handler for doing the actual writing to the hard drive. I have tested it locally on the file server machine and it works fine.
I have root level access to both servers so I can make any changes required.
I'm not a Silverlight programmer, but I might be able to help here... Browser security prevents pretty much any cross-domain actions like this. It's to prevent phishing.
What you could do to get around this is to create another hostname on the same domain as your webserver and proxy any requests on your webserver to your file server. That would get around the cross-domain problem.

cross-domain problem

I am using a silverlight with wcf and when I use the .web project then it runs but when use the silver light project to run the following exception throws:
An error occurred while trying to make a request to URI 'http://localhost:9000/Services/BLWCFSvrc.svc'. 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 want to use the silverlight project to debug my code
Thanks in advance
In order to access network resources from Silverlight, the domain hosting the resource must provide a client access policy file; this is designed this way for security reasons. See here for details: http://msdn.microsoft.com/en-us/library/cc645032%28VS.95%29.aspx
I think your problem is different that just having the clientaccesspolicy.xml, the fact that it runs under the web project, means that you are delivering policies, if you have those added as seperate files under the web project then they wont be deployed when you run the SL3 app seperately, but im sure you figured this out and you're delivering the policies via WCF using webHttp binding (RESTful style), if not, you should.
I think the problem is that when you run the webproject, it builds to your local IIS and executes from there, IIS will allow the SL3 app to communicate with ports/addresses different from the ones that the site is hosted on
when you run SL3 app natively, VS2008 auto generates a test html site for it to be hosted in with some default settings, and uses VS2008 built-in hosting service, which does not allow communication to an address/port different from that of the hosting address. (even though Silverlight is a client side library, VS2008 can do this)
so if you want to run the Silverlight application natively, meaning actually executing the XAP, you can deploy it to IIS, and configure IIS to deliver XAP files, or just install it and run it out of browser and let it update from IIS the deployed version
Just copy a clientaccesspolicy.xml file (for an example take a look at this post; you can even use this sample) into the root of your webserver (eg: c:\inetpub\wwwroot\).
This should help.

Silverlight, deployment, ports, cross domain policies, & endpoints

I made a simple Silverlight app, with a web service calling a database, and got it to work on my development computer.
When I published the web service project to IIS, on the same computer, and accessed the Silverlight app from IIS using http://localhost/SilverlightTest/, I could see the Silverlight in the page, but the call to the web service was not working.
So I added the file clientaccesspolicy.xml in several places. All of the instructions say to put it in the root directory, so I tried:
c:\inetpub/wwwroot\ Did not work
c:\webs\SilverlightTest\ This the folder to which I published the web service project, including the xap file. But did not work
c:\webs\ Just a guess, but that did not work.
Then, in VS, I added the file to the web service project, and that added it to the folder where the web service project is stored c:\work\Silverlight\TestWCF\TestWCF.Web\ . When I opened the page in Firefox from IIS, the call to the web service now worked. Apparently, the Silverlight application is calling the web service in my development folder, not the service in the IIS virtual directory c:\webs\SilverlightTest\ (He call to the web service did not work when I opened the page from a different computer in the workgroup)/
Why would the Silverlight application call a web service in a development folder? Shouldn't the web service be in the virutal directory to which it was published? How can I resolve the confusion?
Here is the configuration in my ServiceReferences.ClientConfig file
<client>
<endpoint address="http://dellnov2006:2753/SimpleWCF.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISimpleWCF" contract="SimpleWCF.ISimpleWCF"
name="BasicHttpBinding_ISimpleWCF" />
Any help, explanation, or pointers to relevant articles would be greatly appreciated. An article explaining how Silverlight apps call web services would be greatly appreciated.
Thanks
Mike Thomas
In your config file, the endpoint address is http://dellnov2006:2753/SimpleWCF.svc
So it seems that you are trying to connect to that address.
Before you publish the application you must modify that address to http://localhost/Service/SimpleWCF.svc or something to point exactly to your service.
The clientaccesspolicy.xml must be in **c:\inetpub\wwwroot** But you need this file only if you will access the service from different host that it was downloaded. I don't think you need it in your case, if you want to use localhost on the local iis.
The address in the ClientConfig is the address of the service you "Added Service Reference" against. As you noticed, it's not a relative path. To overridde this behavior, specify the URI of the address in the constructor of the Service client.
Also, you really need Fiddler. You'll love it. It helps with these issues as well as cross domain issues.
Many thanks djjoyro. You were right. Changing the config file to:
endpoint address="http://MachineName/SilverlightTest/SimpleWCF.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISimpleWCF" contract="SimpleWCF.ISimpleWCF"
name="BasicHttpBinding_ISimpleWCF"
worked, and without a client access policy file. This also worked when I accessed the Silverlight app from other computers in the workgroup.
I also tried using localhost instead of the computer name, but I did have to use a clientaccesspolicy file, and I could not access the web service when using other computers in the workgroup.
There is a lot more I need to know about this, but at least deployment is now working after several days of struggling.
Mike Thomas
Late to the party, but I will add that if your binding address includes a port #, then you are still using the Visual Studio web server. http://dellnov2006:2753 is a dead giveaway that you still using the VS web server and not IIS as you intended.

Resources