I don't want to set the same username and password 100 times for ClientCredentials. I want a pattern where I can set this once in code then have it automatically set.
How do people typically do this? Do they inherit from the wcf class? Do they use partial classes?
Delegate the responsibility of creating the proxy instance to a separate class. This class can have method to create proxy, assign credentials and return the proxy instance back.This is something similar to creating factory classes for construction of an object.
Related
I have an issue in which I wonder if Restangular has support for. I have a UserModel which is part of my model layer. It may have custom attributes that the server doesn't have in it's model and also behavior. I'm not clear if I'm able to use my custom User model, send it to the backend and when it returns transform it back to the UserModel object of my model layer so I still have the custom attribute and methods.
Here's the plunker: http://plnkr.co/edit/IlYcSRuX3GPWmewxniuq?p=preview
Where do I handle the transformation? Do I add the methods in the config block or should I add it via adding a response interceptor? What about custom attributes that the server might not send back to me? I haven't run across any good examples of this.
The UserInfoCntrl controller sends the UserModel object into the contactInformationService in my example.
Some of this might be design choices, i.e. use what you think is best. However, a common pattern [citation needed ;)] would be to integrate the synchronization logic between client and server in the "model" service.
The UserModel service would then be responsible for providing the User object to the rest of the application, keeping it in sync with the server (perhaps via methods like save(), or perhaps automatically?). The service would then be the only module responsible for communicating with the server, at least when it comes to user objects. It can also automatically pull the user data from the server when instantiated.
The architecture feels very clean, at least to me.
I don't have any concrete examples that exactly suits your needs, but this authentication service by Fnakstad springs to mind. It maintains a object (actually a user object!) using $http and $cookieStore. Restangular is a bit more high-level than $http, but the self-contained service concept providing methods for manipulation and storing stands.
I've created my own role provider in a SL4/RIA Services application, and I have had success using the [RequiresRole] attribute on a Domain Service call. I can set a breakpoint in GetRolesForUser and see that it works.
This leads me to some other questions:
How and/or where do I use the other overridden methods in the custom provider? Is it possible to use them within domain service calls? If so is it simply a matter of creating a new instance of the RoleProvider, calling the methods on it, etc.?
Within the custom role provider, is it possible to make domain service calls? If so, same thing, do I simply create/use a new instance of the entities ObjectContext?
Can the AuthenticatedUser instance be hooked into the role provider somehow? I see it has a .Roles property and an .IsInRole method, but can that class be extended somehow to hook into the custom provider?
Any direction on these questions is greatly appreciated.
I've started out with the Silverlight 4 Navigation Application template (RIA Services enabled). (As I really don't like the bloated Business Application Template)
I've added an Authentication Service and I'm able to authenticate users,
but want to override the User.IsInRole method.
WebContext.Current.User.IsInRole("Guest");
But I cannot find any place to override the behaviour.
What are you trying to do? User.IsInRole is an implementation of IPrincipal.IsInRole and really shouldn't be overridden.
If you want to set the user roles, you can do it on the server in your AuthenticationService by overridding the GetAuthenticatedUser or GetAnonymousUser methods.
If you want a method similar to IsInRole, you can extend the User type with a partial class on the client and add whatever methods make sense.
I'm making a Silverlight 4 application with WCF RIA Services.
On the server side (the *.Web project), I have an Entity Model that's auto-generated from a SQL Server database.
On the client side, I have the domain service and proxy objects that are generated by Visual Studio for use in Silverlight assemblies.
I want to add custom properties to the model (preferably on the server side).
Say I have Contact, Company, and Address tables, which are linked by foreign keys (but not necessarily actual foreign key constraints). I want to add a property that will return a Contact's Company's Address object.
I have been attempting to do this by making a partial class to extend the Contact class, and adding a CompanyAddress { get; } property. But I have no idea what I need to do with the new property in order to make it propagate to the auto-generated code on the client side. Are there specific attributes I have to add to the property? Do I have to register it somewhere so that the code generator will know about it?
Does this have to be a Navigation Property or can it be something simpler?
And is this even the best way to do things, or should I give up on extending the server-side model and just do it on the client side? (If I do it on the client side, I face the problem of not having access to the context object inside the individual Entity-derived classes.)
I have never used Silverlight or RIA services but I guess it will be quite similar. When you create EF model and you have entities related by foreign key (there has to be relation), each entity related to other entity will contain something called navigation property. So in your scenario Contact should contain property named Company and Company shoud contain property called Address. You can isntruct EF to load those navigation properties by using Include on ObjectSet or by lazy loading (not good idea in WCF). Than if you send Contact by WCF to the client, Company and Address will be send as well.
Your approach has one big problem. Your property contains only getter - such property is not serialized.
I would like to ".NET RIA Service"-enable my custom data model (BLL/DAL). Are there interfaces I have to implement to enable this functionality or all I have to do is create a Domain Service? If so, how can tell my Domain Services about my BLL? For Astoria, one has to implement IQueryable and IUpdatable interfaces for CRUD capabilities. Is this the same for RIA Services?
All you have to do is create a DomainService. The DomainService will have methods like GetMyObjects() and InsertObject(MyObject object) that either return or accept objects for your BLL - that's how you tell the DomainService about your classes. Your Get***() methods in the DomainService need to return a generic IQueryable, but you shouldn't need to implement it yourself. There's an AsQueryable() extension method that I believe you can use on a generic List, IEnumerable or Array that will convert any list of objects to an IQueryable. It should be reasonably easy to create a DomainService to wrap your existing BLL. Brad Abrams's has a great post describing this scenario: http://blogs.msdn.com/brada/archive/2009/07/22/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-part-6-poco-and-authentication-provider.aspx