Accessing MVC 4 MembershipProvider in a WPF application - wpf

I have an MVC application which creates an SQL DB using Entity Framework, and provides access to this via a WCF DataService. I also have a WPF application which I would like to use to control the MembershipProvider functions of the MVC application, e.g. register new users, update usernames/passwords, etc.
I've looked over a mess of material on using the MembershipProvider functions to provide security within a WPF app, but I'm struggling to find anything on how to access the MVC functions from WPF.
Is this possible using a WCF DataService, or something similar?

Related

How to communicate between the viewmodel and model if model is in separate project in WPF client application?

I am new to WPF and Entity Framework. I am planning to follow MVVM pattern in a WPF client application and Entity Framework for model. For security reasons I don't want to include the entity framework reference in the client application. I have the following query on this front.
In the above case which is the best way to communicate between viewmodel and model?
Well if you really want to separate the application layers that hard, you could create a WCF Service, which loads the entities from the data source and passes it to the client.
You can find some information on creating a WCF Service here. For information about consuming such services you should have a look here. But you will find many articles in the WWW.

ASP.Net MVC AND WPF wioth probably Windows 8 Phone

I am currently developing an application that utlises telerik ORM tools to manage access to a back end database. On top of this layer I am implementing a Business Layer(domain) containing the real world objects that represent my application model.
So far so good.
The issue I have now is one of serious confusion. I will be developing a ASP.Net MVC web site that forms the main hub of my application. In addition to this I have the requirement to create a WPF application that implements some integration into the desktop and lastly I would like to implement a Windows 8 phone app containing a subset of the ASP.Net website functionality but that will also implement some of the WPF functionality.
The problem is I would like to keep the application as simple as possible and maintain a high level of code reuse. Ideally I don't want to implement multiple business layers but I'm not sure of what architectural patterns would be best used? I think adding some kind of service - be it REST, Web services, WEB API or something on top of the business layer and then dealing with each UI technology independently will be the way to go but I thought I'd ask for opinions and advice before I head down a route and end up back tracking?
You could use WCF or Web API as the layer that sits on top of your business layer. If you're looking to use RESTful api, then the new Web API is a good place to start.
If you take a look at these tutorials, they should help: http://www.asp.net/web-api/samples
Your client applications would then call into these API's to communicate with your business / data layer.

Silverlight 3 Tier application validation

I am going to develop the 3 tier application using Silverlight + WCF + ORM
Now my question is if I use ORM at database layer then how can I expose the classes at Presentation, Business layer to do Client-Side validation ?
If you used WCF RIA services instead of plain Silverlight WCF, you can attribute the properties of your data objects (in the associated metadata classes RIA creates for you).
This allows you to add basic validation rules, or even custom ones, that runs on both the server and client.
Using WCF RIA Services via a library is the preferred way to organise projects so try this link:
Walkthrough: Creating a RIA Services Class Library
Also:
Using WCF RIA Services
Creating Rich Business Applications using Silverlight 4 and WCF RIA Services
Various Channel 9 Videos
Is is generally a bad idea to expose your business entities directly to the frontend. Not only is what fits your backend layer rarely a good fit for your frontend but you also run the risk of exposing security critical information to the client - which should never be trusted.
An approach that generally worked well for us is developing the Silverlight Frontend using the MVVM pattern and have your WCF Service Layer return DTOs that can be more or less directly mapped to the data requirements of a ViewModel. This also satifies one of the most important rules when developing intranet/internet client server applications and that is to keep roundtrips to a mimimum because a DTO tailored to the needs of a particular viewmodel can include all the relevant information at once.

Silverlight 4 and WCF

I have a WCF service (using HTTP binding) that our WinForm and WFP apps can use with no problem. We have a Silverlight 4 developer who is saying he's not able to use the WCF service because it needs to be "reconfigured" for Silverlight use. I don't know if this is true or not, because I don't know anything about Silverlight.
So, my question is this. Should a WCF service, that uses HTTP binding, that is successfully being used by our WinForms and WPF applications, also be able to be consumed by Silverlight apps, without modifying or reconfiguring the WCF service?
Silverlight 4 supports the following bindings:
BasicHttpBinding
PollingDuplexHttpBinding
CustomBinding (with a subset of binding elements)
Silverlight and WCF Feature Comparison:
There are several ways to use the WCF
client stack to access a service.
It is used when invoking services
through automatically generated
proxies, as described in How to:
Access a Service from Silverlight. The
proxy must be generated in this
procedure by using the Add Service
Reference tool in Visual Studio 2010
for the Silverlight project.
Caution:
Proxies generated by using the WCF
Svcutil.exe tool will not work in
Silverlight 4. Use the SLsvcutil.exe
tool instead. For more information
about using this Silverlight tool, see
Using SLsvcUtil.exe to Access a
Service.
If you already have a Windows
Communication Foundation (WCF) service
contract definition, you can use the
generic ChannelFactory class without
having to generate a proxy. This might
be the case, for example, if your
client is sharing service definition
code with the project on the server.
In this case you could, for example,
define a service contract interface
IStockQuoteService and then use the
same IStockQuoteService code in both
the server and Silverlight projects.
This would involve using a
ChannelFactory.
This advanced technique is
demonstrated in How to: Call
Operations Asynchronously Using a
Channel Factory and in the Silverlight
4 context with Building and Accessing
Duplex Services. For more information
about defining and using service
contracts, see Designing Service
Contracts.

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.

Resources