Saving Data in a SilverLight Webpage - c#

im trying to perform a simple database insert from a submission on a SilverLight Webpage. Normally i would either use ADO or LINQ to SQL to perform this. You can not do this within a SilverLight Project, nor can you reference a project that can (a non SilverLight project). What would be the best way of doing this?
Thanks.

For the most part, Silverlight apps are designed to talk to web-based data services or databases via RIA services.
There are a a few approaches to your problem:
Reference a web service, like an .asmx or any REST servie
Use WCF to communicate to the backend
Use Silverlight RIA Services to talk to the database (it was designed to solve your problem)

Your best bet is to use the .NET RIA Services which will allow you to define server-side domain classes and due to the RIA Services link, will generate client side code in your silverlight project.

Another alternative if you don't want to use web services, is to Xml Serialization and Isolated Storage to store the files. You'd simply load the database into memory on startup, and then persist to the file when the apps closes, or periodically.

Related

Accessing an SQL database from a Silverlight client (no web project)

I want to access a remote SQL database for my Silverlight client. I know that there are various ways to do this (Entity Framework model, Linq to SQL), but all of those rely on something in the web project (or, at least, all of the tutorials I've read do). What's unusual for me is that there is no web project, which of course prevents me from using various assemblies.
The only thing I do have which might be useful is a WCF service running on IIS, which will have less limitations (and I can add that as a service reference in my SL project). But I'm not even sure if this is a feasible option for this problem.
Any solutions or suggestions would be great.
Thanks.
Edit: Thanks for the suggestions guys, but here's a little more: I am making an individual XAP that is loaded into something else (someone else's project is importing and loading the XAP files), so I don't have access to the web component. The loader itself will be hosted within a website (at least, I assume it will be).
I already have a WCF service set up which is currently hosted in IIS, so I can potentially create something here. How? Well, it seems I can generate the ORM classes using SQLMetal.exe, and then import that code into the WCF service. This will allow the service to make calls to the remote database and have that data returned in C# classes. The perhaps I'll make those data classes as ServiceContracts and pass the data that way. What's the problem here? Well, to be honest, I'm not really sure how it would work. I mean, I call the WCF Service from the SL application, which does its thing. It then must contact the SL application (I have no idea how to do that part) and send along a load of data. It would be great if someone had has experience of this and would offer some suggestions. I know it's not really how you're supposed to do it, but I've drawn the short straw so I'm stuck with it.
Ok, so if I understand it correctly, you use a Silverlight application (XAP) which is started locally from a network share or something? Because why would you not have a web project when using Silverlight? (is there no server available to host it?)
But ok, when that is the case, you can access a WCF service from Silverlight. However it has some limititations. For instance you can only use asynchronous calls to the service, and you can only use WCF basichttpbinding as binding for the WCF service.
See: http://msdn.microsoft.com/en-us/library/cc197959%28v=vs.95%29.aspx
First, I would recommend you use WPF instead of Silverlight for this project. If you're not using this as a web client, then WPF is a million times easier / better.
But if that's not a possibility:
You can write a self-hosted WCF service and run it somewhere accessible. Self-hosted will allow for WCF connections to connect without the IIS necessary. In your self-hosted program you need:
Front end WCF defined
Back end SQL database
Depending on how smart this client needs to be, a BusinessLogic layer to transform the data from WCF to SQL.
Silverlight is sandboxed, so it can only access its own Web application. Therefore, your best bet is to include a WCF or ASMX web service in your web application that handles the DB access.
If you don't want to run a sandboxed UI on a Web application, you cannot use Silverlight but should use WebForms or Windows Presentation Foundation (WPF) instead.

Complications in integrating Silverlight and existing asp.net application?

I am new to silverlight, WCF RIA services. We have a medium size financial business web application. There is a lot of code. The code is well organized with lots of business objects, web controls, web forms, Data Access layer, Business logic layer.
There is a requirement for some enhancements to the web application and one of the team member wants to use silverlight to improve UI and responsiveness.
We tried to integrate a small silverlight application in the web application, But what I found is we copy the xap file and it always opens the Main form.
how can we open other silverlight controls?
How can we use the business objects and business logic with the silverlight as the silverlight supports on silverlight class library?
How can we use the existing data access library?
How can we connect to the database? I saw WCF RIA services, all the examples I saw with entity framework and we use oracle and the cannot use the beta version of oracle entity framework?
how to pass data to & from silverlight app to asp.net?
There maybe some other issues which I am unaware.
Thanks, Naveen
how can we open other silverlight controls?
You would create a Navigation Framework based Silverlight application. This allows the use of a path following # in the URL to navigate to other pages within the Silverlight application.
How can we use the business objects and business logic with the silverlight as the silverlight supports on silverlight class library?
You won't be able to use them directly. Here you would create a Silverlight WCF service to access your business objects, you keep the business objects on the server.
How can we use the existing data access library?
You don't, you are going via WCF to your business objects which are on the server and from there on to your data.
How can we connect to the database? I saw WCF RIA services, all the examples I saw with entity framework and we use oracle and the cannot use the beta version of oracle entity framework?
As above, the Silverlight app only sees your specialist WCF Service.
how to pass data to & from silverlight app to asp.net?
You can do that via your business objects and/or your new WCF Service.

C# architecture for long-lived data collecting server apps

We are about to start a new project for a server application, for the purpose of collecting data from several data sources and storing it in a database.
For a quick test, we created a WinForms app which uses the core functionality from a custom library, and now have to start migrating it towards the final product.
From what we've done so far, the best way to do this should be to make it a Windows service and then expose basic monitoring and configuration to a thin Win or Web client through remoting/web services.
Is there a more appropriate way to make such an application?
You could consider exposing the service itself using the WCF/ADO.NET Data Services: http://msdn.microsoft.com/en-us/library/cc668792.aspx
Also see this for a quick walkthrough on how to expose a WCF Data Service: http://www.msteched.com/2010/NorthAmerica/DEV324

KISS: Simple C# application which communicates with a RESTful web service

Following the KISS principle, I suddenly realised the following:
In .NET, you can use the Entity Model Framework to wrap around a database.
This model can be exposed as a web service through WCF.
This web service would have a very standardized definition.
A client application could be created which could consume any such RESTful web service.
I don't want to re-invent the wheel and it wouldn't surprise me if someone has already done this, so my question is simple: Has anyone already created a simple (desktop, not web) client application that can consume a RESTful service that's based on the Entity Framework and which will allow the user to read and write data directly to this service?
Otherwise, I'll just have to "invent" this myself. :-)Problem is, the database layer and RESTful service is already finished. The RESTful service will only stay in the project during it's development phase, since we can use the database-layer assembly directly from the web applications that are build around it. When the web application is deployed, the RESTful services are just kept out of the deployment.
But the database has a lot of data to manage over nearly 50 tables. When developing against a local database, we can have straight access to the database so I wouldn't need this tool for this. When it's deployed, the web application would be the only way to access the data so I could not use this tool. But we're also having a test phase where the database is stored on another system outside the local domain and this database is not available for developers. Only administrators have direct access to this database, making tests a bit more complex.
However, through the RESTful service, I can still access the data directly. Thus, when some test goes wrong, I can repair the data through this connection or just create a copy of the data for tests on my local system. There's plenty of other functionality and it's even possible to just open the URL to a table service straight in Excel or XMLSpy to see the contents. But when I want to write something back, I have to write special code to do just that. A generic tool that would allow me to access the data and modify it would be easier. Since it's a generic setup around the ADO.NET Data services, this should be reasonable easy too.
Thus, I can do it but hoped someone else has already done something similar. But it appears that there's no such tool made yet...
You are referring to ADO.Net Data Services. It basically creates an Entity Database Model and adds a REST frontend to the service using ASMX. There is a How To article availble from MSDN here on consuming the service using .Net. I have also done the same thing using the normally WebClient class in .Net in the past.
You can also look at the WCF REST Starter Kit if you want to roll your own based on Entity Framework. The starter kit also contains a handy new WebClient class that can be used to communicate with REST services.
Clarification
There is no prebuilt application client that I am aware off which will talk to these service, since they are pretty much accessing the data using Web Services. There is the Microsoft Smart Client Factory which is most likely the closest thing I have worked with.
I mentioned the above 2 options since they already have libraries in .Net that work with them directly, either as a referenced Web Service, or for the more adventurious, myself included, using the WebClient library or alternatively the new HTTPClient library in the WCF REST Starter kit.
I have used both, in Windows, Web, Silverlight and WCF. The latter being the easiest since they are focussed at REST.
We are currently investigating Prism which strongly leans to using this method when using WCF for front-end development.
Assumption
With regards to this question, you are making a generic assumption that wrapping ADO Entity Framework with a WCF service it will be generic. ADO.Net Data Services is the closest you will get, however the structure of the database will fundamently change the way you interact with it. Going a level higher in a "generic" way would be dangerous, as these 2 technologies, individually or together, are already as generic as possible.
In addition to Data Services (+1), consider RIA Services. It's like a domain-specific version of data services for Silverlight or WPF clients. Less flexible, but easier, than Data Services.

Upload Data from .net Windows Form Application

Sorry, if this sounds ignorant. Is it possible to SECURELY upload data from a Windows Forms app using an asp.net web service or some other method? If so, what is the general way of doing it?
I have never used web services before.
I have an IIS 6 server with .net 3.5 installed. I need to build this windows forms program, which will hold data in a local sql compact database. When the program has access to the internet, the user needs to be able to MOVE the local data to a database on the web server.
What ways can I go about doing this? Am I on the right track thinking about web services? I have also read a bit about Sync Framework, but I'm not sure if that is all that well suited for this.
Thanks for suggestions.
EDIT
I forgot to ask: Would WCF be a possible useful technology?
Yes. Just secure the web service by SSL.
WCF can be a useful technology too. You might also want to consider SQL Server merge replication.

Categories

Resources