This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi guys, I've run into a couple of issues with WCF RIA.
1. In the post on your Facebook wall, you've attached a link to a demo project with WCF RIA. The link required Silverlight Elements 2 to build. I've downloaded SE2 + latest nightly build for LS4 beta at the time I was buiding it. I got the whole thing to build (which thankfully wasn't hard at all). The WCF RIA client code only generated the web context related stuff, no entities (Films / Cinemas etc) were generated client side.
2. I took Tim Heuer's buisness application project template for a spin, changed the service side stuff a bit and added LightSpeed.
My Service Code :
using ICode.Data.Authentication; using Mindscape.LightSpeed; using Mindscape.LightSpeed.ServiceModel.DomainServices; using System; using System.Linq; using System.ServiceModel.DomainServices.Hosting; using System.ServiceModel.DomainServices.Server.ApplicationServices; using System.Web.Security;
[EnableClientAccess] public class AuthenticationService : LightSpeedDomainService<ModelUnitOfWork>, IAuthentication<User> { public User GetUser() { if ((this.ServiceContext != null) && (this.ServiceContext.User != null) && (this.ServiceContext.User.Identity.IsAuthenticated)) { return GetUser(ServiceContext.User.Identity.Name); }
return AuthenticationService.DefaultUser; }
public User Login(string userName, string password, bool isPersistent, string customData) { //System.Diagnostics.Debugger.Break();
if(this.ValidateUser(userName, password)) { FormsAuthentication.SetAuthCookie(userName, isPersistent);
return GetUser(userName); }
return null; }
public User Logout() { FormsAuthentication.SignOut(); return AuthenticationService.DefaultUser; }
public void UpdateUser(User user) { if ((this.ServiceContext.User == null) || (this.ServiceContext.User.Identity == null) || (!string.Equals(this.ServiceContext.User.Identity.Name, user.Id, StringComparison.Ordinal))) { throw new UnauthorizedAccessException("You are only authorized to modify your own profile"); }
var uow = this.DataContext.CreateUnitOfWork(); User match = uow.Users.Where(u => u.Name == user.Name).Single();
match.FirstName = user.FirstName; match.LastName = user.LastName; match.Password = user.Password; match.PhoneNumber = user.PhoneNumber;
uow.SaveChanges();
}
#region Private Methods private bool ValidateUser(string userName, string password) { return DataContext.CreateUnitOfWork().Users .Any(u => u.Name == userName && u.Password == password); }
private User GetUser(string name) { return this.DataContext.CreateUnitOfWork().Users.First(u => u.Name == name); } #endregion
#region Private Members private static User DefaultUser = new User() { Id = string.Empty, Password = string.Empty, Email = string.Empty, PhoneNumber = string.Empty, FirstName = string.Empty, LastName = string.Empty, IsActive = false, Roles = null }; #endregion
protected override LightSpeedContext<ModelUnitOfWork> CreateDataContext() { return DatabaseContext.LSContext; } }
The LightSpeed model is in a separate assembly, I'm using a static class to expose it :
using Mindscape.LightSpeed;
public static class DatabaseContext { const string ls_conn_string = "server=localhost;User Id=root;Pwd=1deathwing;Persist Security Info=True;database=icode.tests";
public static LightSpeedContext<ModelUnitOfWork> LSContext { get { lock (mLsCtxPadlock) { if (mContext == null) { mContext = new LightSpeedContext<ModelUnitOfWork>(); mContext.ConnectionString = ls_conn_string; mContext.DataProvider = DataProvider.MySql5; mContext.IdentityMethod = IdentityMethod.IdentityColumn; }
return mContext; } } }
public static ModelUnitOfWork Context { get { lock (mCtxPadlock) { return LSContext.CreateUnitOfWork(); } } }
private static LightSpeedContext<ModelUnitOfWork> mContext; private static object mCtxPadlock = new object(); private static object mLsCtxPadlock = new object(); }
When calling the service's operations client side I'm getting "Not Found" responses from the server. Those responses were received in 2 cases I've tested : On manual login (not found) and on WebContext.LoadUser() (when user clicked "remember me" and the LoginInfo passed to the service contained a Persist=true.
I'd apreciate if you could look into this, If you need a more concrete code sample, let me know and I'll be happy to provide it.
Best regards, Maciek
|
|
|
A concrete example would be great if you are able to send that through, in the meantime I will have a look at this later on today based on what you have pasted in. In terms of the client side code, this should be generated for you once you add a Data Source, as it normally does with RIA Services - can you elaborate on what steps you took which saw it not generating? Also with the sample which I posted, the client side code should have already been generated - did you get an error on this with the initial compile?
Thanks! Jeremy |
|
|
Regarding the initial compile - yes that is correct. As far as I recall the steps were :
1. Download the sample's source code 2. Realize that it requires Silverlight Elements2 after first compilation attempt 3. Download SE2, fix all references 4. Attempt to build again - compilation error .Web namespace missing client side, entities not present, WebContext present
It's not much but that was a while ago. Regarding the authentication sample, I'll deliver some code over the next few days once I'm back home. Where should I send it? |
|
|
I'm attempting to compile the RIAServicesExample again,
I can't get the ModelDomainContext to show in the Data Sources window, no idea what to do - hints? |
|
|
You can either attach it to the post or email it through to support at mindscape.co.nz :) Sounds like the Visual Studio code generation for the client side code is a bit messed up from what you have described there. I am guessing you dont have any other references added?
Thanks! Jeremy |
|
|
The only references that are present are the ones that came in the package, I haven't added anything new. Just made sure that the following assemblies are present server - side :
|
|
|
Working on the authentication sample, just takes a bit longer because I've managed to contract flu. No worries though, I'm still on it. |
|
|
I've sent some code over to the address you've provided, have fun. |
|
|
I'm facing exactly te same problem with the latest nightly builds, any suggestions yet ? Thx |
|
|
I haven't tried the latest nightlies yet, but what managed to solve the issues for me was to upgrade VS2010 to VS2010 SP1. Apart from that I tried to set the Ria Services configuration properly, if SP1 doesn't resolve it for you, post here and I'll search my mail box when I get home, in the mean time maybe Jeremy can help |
|
|
Thx for the suggestion. I was allready using VS2010 SP1 but to be sure I reapplyed SP1 but without succes, still facing the same issues. I copied the version info of the visual studio about box : Microsoft Visual Studio 2010 In trying to be more specific I also copied the errors mentioned in the error list box after compiling and accessing the MainPage.xaml of the RiaServicesExample: Error 1 Parameter 'film' of domain method 'InsertFilms' must be an entity type exposed by the DomainService. The entity type can be exposed either directly in a query operation, or indirectly through an association. RIAServicesExample Thx for helping me out. |
|
|
Hi Frank, Does appending the explicit Query attribute to GetFilms (and you would need to do the same to GetCinemas) solve the problem? Ive seen RIA Services get confused at times in finding the IQueryable method to infer that a given type is an entity type.
Jeremy |
|
|
Hi Jeremy, Appending the Query attribute explicitely does solve the problem, not only for the RiaServicesExample solution but also for my custom solution where I as facing the same problem. Strange behavior, however lesson learned. I'll be adding the attribute explicitely in the future. Thanks for the usefull help, Frank. |
|