How to host silverlight on S3 - silverlight

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.

Related

Google Analytics with Silverlight HTTPS cross domain policy problems

I'm sending simple messages to Google Analytics from a Silverlight app. They look something like this (data changed):
http://www.google-analytics.com/collect?v=1&tid=foobar&cid=foobar&t=pageview&dp=foobar&dt=foobar
Very simple API. If I use HTTP it works beautifully.
If I use HTTPS, I run afoul of Silverlight's cross domain policies. According to the docs, google-analytics.com needs to approve the cross-domain call by hosting either a clientaccesspolicy.xml (Silverlight-specific) or crossdomain.xml (original used by FLASH). Turns out they do host crossdomain.xml, and I can see that Silverlight downloads it (via Fiddler), but apparently Silverlight doesn't like the file's content and doesn't allow HTTPS calls to that domain (System.Security.SecurityException).
So.. at least at the moment, I can't use Google Analytics from Silverlight using HTTPS. Does anyone know a work around for this issue?
Note, I can't just use HTTP, because that causes IE to issue a "Allow Mixed Content" prompt which causes problems for some of our customers. I need to use HTTPS like the rest of our app.
EDIT: OK, I took a totally different approach, using HtmlPage.Window.Invoke to call a 3 line Javascript function to do the asynchronous send rather than using WebClient in the Silverlight code. Works like a champ. Anybody see any potential problems with that?
I suspect there may be a way to make this work, because I know google-analytics.com is very cross-domain friendly for exactly this reason.
If you absolutely can't get it to work another option would be to proxy the hits. If you do this, you'll want to make sure to use the ua and uip override fields in the hit you're sending so that they show up in Google Analytics with the IP address and User Agent of the original visitor and not your server.
Here's some more info on using a proxy server with the Measurement Protocol:
https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#using-a-proxy-server

WCF Silverlight crossdomain problem

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).

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.

Deploying a Silverlight Application with built-in ASMX WebService to IIS

I've got a Silverlight application which uses a built-in .ASMX WebService to access a SQL database and run some queries. Everything runs without any hitches on my Development machine.
I'm trying to deploy the application to IIS 6 and I'm having some issues.
The Silverlight application itself seems to run fine, however the Web Service does not. I get an unhandled exception error that says [Async_ExceptionOcurred] as soon as the page loads (when the page loads I'm making some Async WebService method calls).
I think this is an issue with the Web Service but I don't know what the problem is. I tried setting the WebService namespace to my URL, but that didn't work. I've tried messing with the SQL connection string in my Web Config but that also affects nothing.
One thing to note is that my IIS Virtual Directory only contains my SilverlightApp.Web folder. I know that the other folder that's part of the application contains a .ClientSettings file for the WebService, but I think this is embedded into the .xap.
Can anyone shed any light on this?
The most likely thing that's happening:
Your webservice proxy on the client is using the address of the web service it was built against: ("http://localhost...").
Things to do:
Use fiddler to confirm this is the issue. It will show you where the proxy is making the call to.
Use the overloaded constructor for the web service and specify a URI. Consider using id/deffing for debug/release. This will overwrite the settings in the client.config.
Create another endpoint in the client config for the release build (Shawn's article here) and select one or the other (again using if/defs).
There are other options as well (looking at the URI and building up the service adress)... but that's the general idea.
hth,
Erik

Resources