Access Application level settings in Silverlight Project - silverlight

I have solution containing silverlight project, wcf service project and other projects of C# i want to have one app settings file from where all projects can load settings. Which will be useful in case of db interaction, logging etc..
Currently i m changing all app settings file in all projects.

I have used Nini successfully for some time now. It allows you to put all your config settings in a central file which can then be referenced from all your server-side projects, be it web applications, scheduled jobs, wcf services etc. For the Silverlight client apps, I created a WCF configuration service. All the different Silverlight apps access this service at startup to load their settings. This means that the server-side apps only need to know the location of the Nini configuration file, and the Silverlight clients only need to know the url to the configuration service (transferred through the in the .aspx page). The configuration service then accesses the Nini config file and returns a collection of ConfigurationSettingEntity objects. These just contain a key and a value. Of course it is of extreme importance to make sure that all sensitive settings (e.g. db connection strings) are never transferred over the configuration service. Nini allows you to divide your config file into sections. I have three sections currently. One for the Silverlight clients ("ClientSettings"), one for server-side settings only ("ServerSettings") and one that contains any shared settings ("CommonSettings"). This way you can make sure that the configuration service never returns anything from the ServerSettings section. This has worked really well for my purposes.

Have a look at Configure Silverlight 3 Applications using the Web.config File from ASP.NET

Related

Sharepoint with silverlight app

I am new to Sharepoint. I wrote a simple RIA MCF silverlight app which runs all the queries right on my server. Now I tried make it available on a Sharepoint testing site. I loaded the xap file but Sharepoint throws me tons of load operation exceptions when it tries to load the app, apparently having problems with the EDM in the app. What do I need to do here? Is the xap the only thing I need to load on the shared documents folder?
Thanks.
Justin,
There are few steps you need to follow to load the Silverlight XAP in sharepoint.
You need to create RIA service as an independently hostable web application (.svc)
Follow the guidelines available here
Once you have the solution ready. Host service on IIS and make sure that it is functioning correctly.
Configure the .svc in the web.config of the hosting web application and access the same in your silverlight application as below
new LoggingContext(new Uri(ConfigurationManager.AppSettings["LoggingServiceUrl"]);
Load the xap on sharepoint site and in the configuration section provide links to .svc services.

How do I dynamically detect what hostname/port to connect to find a WCF service when debugging in VS

WCF service is hosted in a website in the same solution as my WPF client.
Given that the development webserver often switches ports, I was wondering if there was an easy way to detect this so I don't have to keep hardcoding / updating my config?
The web project properties page contains option to specify an exact port on which the development server would run. Check the 'Web' property page.

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

RIA Services Authentication - What type? Preventing "copies?"

I've got a Silverlight application that will be running out on the open internet, available to basically everyone who has ever lived.
The application makes use of RIA Services to manipulate data in a database on the server.
The application creates, reads, updates, and deletes data of different varieties, however I only want these operations to occur from within the application.
This brings about two questions:
Is there a particular recommendation for what type of Authentication to use? Forms or Windows?
Is there a way to prevent someone from "linking" to the application? That is to say, copying the HTML from the containing page, pasting it in their own HTML page on their local machine and running it? The end goal would be to only allow the application to be run when it is embedded in a page requested directly from my server and my server alone?
If your application is being used on an internal network, then Windows authentication is best. Otherwise (as is your case) use Forms authentication.
Silverlight automatically prevents applications (unless they're running with elevated trust) from accessing resources on the Internet (web services, HTML, etc) that are not from the domain that the application originated from, unless that domain has a cross-domain policy file in its root. The Silverlight runtime prevents this (not the server), so this a client based security feature - not server based. By not having a cross-domain policy file in place on your server, your application will only be able to communicate with your domain services when it is run from your server (as you are after). The application will run, but calls to those services will fail.
You could always do a check for what domain the application originated from in code, and match it to a hard-coded domain name if you want to prevent the application running at all from other domains.
Hope this helps...
Chris

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.

Resources