deploying services to use SQL server in silverlight - silverlight

I've made a service for my silverlight 4 database (SQL) affairs (VS2010, C# ASP.NET web app), now I'm writing my SQL functions in this service, how can I use this functions? I've read some articles about deploying services but I think my case should not be much complicated, I have a big ASP.net web app with several web pages (I have a server running on winserver2008), it works great, also I have a SL app, what kind of files should I upload for using service? do I need an asmx? how can I create it? should I change anything in web.config?
what is the easiest way to use my service for communicating between SQL and SL? thanks

WCF RIA Services is the way to go. You do not want to bother with old-school ASMX web-services.
You will use an EF model and a DomainContext on the server to handle all database access via CRUD methods (Create, Read, Update & Delete).
On the client you will use the generated Domain Service client to access data.
Notes from my previous RIA post:
My suggestion is to always create RIA Service libraries instead of adding directly to a Silverlight application. Then you can link the Client-side library to any number of Silverlight applications, then link the .Web part of the RIA library to your website to provide the WCF service. Again the key is to migrate the config settings.
It will probably make a lot more sense if you create a new RIA services library project, add your EDM etc, then link the halves to a separate Silverlight app and your new ASP.net website.
Step-by-step:
Create RIA Services Library project by selecting Add New Project. Select Silverlight on the left. Select WCF RIA Services Class Library on the right. I will assume it is called the default name RIAServicesLibrary1 for this example. It will create a Silverlight client library called RIAServicesLibrary1 and a standard .Net library called RIAServicesLibrary1.Web for use by the Web server.
Add your EDMX to the RiaServices.web project. Select Add new item. Select Data on the left. Select ADO.Net Entity Data Model on the right. I will assume it is called the default Model1.edmx for this example. Connect it to your database tables etc.
Build your project so that the next step will find your data model.
Create a Domain Service referencing your EDMX models in your RiaServices.web project. Select Add new item. Select Web on the left. Select Domain Service Class on the right. I will assume it is called DomainService1.cs for this example. Choose your data items from the Add New Domain Service Class popup window by ticking the checkboxes. A set of RIA services objects and methods will be created for each item you select.
Add a reference to the client Ria services library project (RIAServicesLibrary1) to your Silverlight application.
Add a reference to the web RIA services library project (RIAServicesLibrary1.Web) to your hosting web application (e.g. you ASP.Net website).
Copy/merge the various sections in the RIAServicesLibrary1.Web/app.config file into your <webapplication>/web.config file. This will include any connection strings and the module sections.
Build the project again so that the Data Source window will see your new Domain Context data sources.
Use the RIAServicesLibrary1 client object (called DomainService1 in this example) directly from your Silverlight code like this:
DomainService1 client = new DomainService1();
or use the Data Sources window to drag/drop a new grid etc onto a page.
If the Data Sources window is not visible select the "Data" menu then the "Show Data Sources" option.
For more information try this Microsoft link: Using WCF RIA Services

Related

Silverlight + Custom RIA Services

Good day!
I'm developing a Silverlight Solution with a lot of projects that uses RIA Services. Each silverlight project have Silverlight + Own Ria Services project. I want to make only one RIA services project and all silverlight project consume it.
The problem is when I set the "WCF RIA Services Link" to the new RIA Services, the Silverlight project works ok, my ViewModel class works ok, but, when I'm running, the application give me the error:
"Load operation failed for query 'GetList'. The remote server returned an error: NotFound."
When I test on the browse http://localhost/Project-Web-Services-Patrimonio-ClassService.svc runs ok.
How can i do to make it ok?
[]'s
Tiago Schäffer
I think you will find you are missing the RIA services web library config settings in your web app.
Taken from my answer here. Key notes in bold.
Use the RIA services project option to create your service library. That creates 2 projects that are bound together (for code gen of the proxy objects). Both are effectively just libs (1 Silverlight and 1 .Net)
Link any RIA services client library to you Silverlight app. Then link the .web RIA project to your hosting web app (for the standard RIA use). You can also add the .web library to your Wcf service as a .Net lib (not consume it as a service).
If you did not create your main Silverlight project as a RIA services project you will need to move the settings across from the app.config file to your web.config file. If you already have the service support settings you only need to copy the db connection string across. The db connection string only should be needed for you Wcf project.
You should then be able to either use the server-side RIA calls (don't forget to add your own submitchanges calls as RIA does that behind the scenes once per batch of updates), or just use the data layer (EF etc) directly.

Add web project to silverlight application - how to

I have created a WCF Service application, which contains a reference to a service I created.
I want to add this service application as the web component of my SL application, but I can't seem to find the option that allows me to do this.
Can someone help me out here?
Thanks.
I think you need to create a web site, then add a reference to the WCF Service from the website. You could also just have the .svc file in the website. Then right-click on your Silverlight application project and Add Service Reference. This will generate the Reference.cs (show all project files and expand the service reference to see) that will contain all the classes that you exposed in your WCF Service through return or paramaters in your methods.

Stuck with MVVM Architecture Problem

I am building a silverlight application using MVVM pattern but I don't understand what I am missing here...
ViewsProject (Silverlight Application) contains user controls and page. References ViewModelsProject.
ViewModelsProject (Silverlight class library) contains backend code of views. Also the business logic will reside in here. It will reference Models project.
ModelsProject (Windows class library) contains: Ado.net entity model of a local database and a WCF RIA DomainService built on the entity model. It's purpose is to get data from the local database and the entities are exposed via domain service.
Web project: Contains xap of ViewsProject.
Have I done everything correct so far? If yes then please help me understand:
How do I call the methods of the
domain service in the ViewsModel
project? If I reference the
ModelsProject, I get the error that
only silverlight projects can be
added.
If I change ModelsProject to a
silverlight class library project
then I can't add the entity model of
my database.
For client projects to use WCF RIA Service you need to set WCF RIA Services Link in project property.
As for modularity and separation in project architecture when using WCF RIA Services,
you can use WCF RIA Class libraries.
There isn't much sense in separating your views from your viewmodels IMHO. I've seen this approach used before but the view model (in my mind at least) represents a more 'view appropriate' abstraction of the data than the domain model can offer. The ViewModel provides a layer of indirection to allow the presentation to change without the model doing the same but it's little more than a sort of Adapter/Controller hybrid and lives alongside the view.
To answer your question though...
Typically, you'll have your SL project call your domain service (a web service usually) via commanding from your view to the viewmodel. The viewmodel command will then directly or indirectly make the web service call. This web service does not need to be a SL class library since it sits on the web server away from your client.
I get the feeling your thinking in terms of a desktop app here. Remember that the SL project runs client side and your data is not there. To wire all this up your gonna need some remote service to get the data from. A regular library reference is no good since the data is not on the client.
HTH, Stimul8d
I worked out the answer.
Change ViewModelsProject (Silverlight class library) to Silverlight Application type.
Check Enable Ria services during creation of the project.
In the view model class, add using ModelsProject.
Compile the ViewModelsProject.
All of the methods of the WCF Ria service will then appear in the code.

SIlverlight and WCF RIA

I have an application where I present the data to the users by using Silverlight 4 and WCF RIA Services. In this application I have also a module (console app) which is responsible to store in the DB some flat files (xml files).
My question is: According to the best practices which one of these two options is the best?
Reuse the WCF RIA Services also for the Console App to store the flat files in DB.
Create others WCF Services specific for the Console App to store the flat files in DB (with ServiceContract).
Any idea? Or other options?
THANKS!
All I can say is it is always a best practice to reuse any code that can be reused. I don't see why you would want to create a whole new service layer for another application? Being reusable (over multiple applications/platforms) is the point of web services.

Silverlight + RIA Services and customing the user/password storage

Using the Silverlight Business Application template in VS2010 creates a nice default solution with a Silverlight project and an ASP.NET project. It also automatically provides some nice authentication that seems to store usernames/password/etc for newly registered users into your local SQL Server database.
Is it possible to customize the storage mechanism? I already have a data store elsewhere and want to handle the adding/removing etc of details myself.
Yes, you can. WCF RIA Services is using the default ASP.NET Membership provider. So search on the web on how to modify them (via web.config) to connect to another source and it will be transparent for the SL/WCF RIA Services application.
For instance, I've connected them to the Azure Storage (table) instead of the default ASPNETDB database on this application : http://cloudypizza.cloudapp.net . You can test it by creating your own account on clicking on "login".
I've briefly explained how I've done it here on my blog (in French only sorry)
Regards,
David

Resources