Csla DataPortal not finding implemented methods (Silverlight) - c#

I am developing a silverlight application that uses CSLA for the business objects.
I'm trying to set up the DataPortal correctly so that it will correctly call the DataPortal methods that are contained in my .Net class library.
I have my Model and Model.Silverlight projects set so the classes in the silverlight project are created as links and my DataPortal methods are all inside #if !SILVERLIGHT compiler directives. The silverlight UI references the Model.Silverlight project and uses Get methods which then call DataPortal.FetchAsync.
Picture of my project layout here http://i.imgur.com/V3pQppa.jpg
My issue is that FetchAsync returns with the error DataPortal_Fetch not implemented, though the method with the correct signature exists inside the #if !SILVERLIGHT block.
This leads me to believe the data portal is not configured properly. I have the web service created and I can browse to it by right clicking > View in Browser. The web service is also set correctly for Csla.DataPortalClient.WcfProxy.DefaultUrl in the App_Startup. So I honestly do not know what else to try.
Hopefully someone can help as the problem has been plaguing me for days and I can't register on the CSLA forums to post there. Thanks in advance!

It seems like my issue was I was missing this line in the App_Startup
Csla.DataPortal.ProxyTypeName = typeof(Csla.DataPortalClient.WcfProxy).AssemblyQualifiedName;
Which seems to have become needed in CSLA 4.5
Now the data portal is finding the implemented methods correctly

Related

Build dynamic user interfaces with Blazor and XML

I've been researching ways to build a Web Client using C# that is Single Page and is generated from XML files.
Essentially, I want to have a service that generates XML files that describe the UI of e.g. forms (not the problem). Those XML files are sent to the client, which in term reads the XML and dynamically creates the layout with all the controls. I had hoped to accomplish this in Blazor WebAssembly (I have also looked at ASP.NET WebForms, MVC and CORE (using DevExpress), but none of those are actually meant for SPA clients).
By comparison: We have an Android app that basically does this, similar to what is described right here: https://developer.ibm.com/tutorials/x-andddyntut/
But this time I am not developing an Android app in Java, this is supposed to be a WebClient. And as most coders in the company have a VB.NET background, my head of department would like for it to use C#. But I have tried finding ways to do something like this and have met lots of dead ends, as usually Blazor appears to be used with static pages from design time. I haven't managed to get it to run with RenderFragments, for example.
Any pointers with this would be very much appreciated!
Sincerely,
MR
You can generate the UI dynamycally using RenderTreeBuilder but most of its behavior is intended for internal use (take RenderTreeFrame for example) and therefore I don't think it is a good idea.
In short, I don't believe what you want to achieve is possible.
If these XMLs don't change often, I would think to create a transpiler that converts these XMLs to Blazor code and then recompile the app.
Not a direct answer to creating Forms dynamically, but a suggested alternative method.
For my application I have a number of services which have different properties but are based on underlying common base class. The services defined in several .NET Standard library for each type. The services are things like VoIP, Broadband, FTTC, Ethernet, Router Orders etc. etc. - not much in common, and very different types of data and behaviours.
The base service class has an abstract method called GetView which returns a C# type which is a Razor Component type. Remember in Blazor all those components are just C# classes. The type returned is a Razor Component in the same library (so we have UI as well as business and entity logic encapsulation).
The parent site loads a specific type of service, calls GetView and binds the service to the resulting Component.
That's pretty complicated to describe but I did a proof-of-concept application for this approach in the early days of Blazor as I realised it was going to be capable of this approach: https://github.com/conficient/BlazorDynamicList
There is also a demo site at https://blazordynamiclist.azurewebsites.net/
I won't explain it all in detail here but it follows a similar approach. There is an abstract base class ProductBase that has an abstract method GetViewComponent. Each product can return its preferred Razor Component to display itself.
The 'magic' is the DynamicComponent.cs which is a Razor Component with a BuildRenderTree method that creates a bound instance of the product's component view.

In C#, how can I get the name of the calling project from within a referenced project?

I have three projects: My.Business, My.WebSite and My.WebService
I need my logging class to be able to identify when a request is made from the website versus the web service. I used to have the web service running as a separate application underneath the web site, so I'd just use different config files, which worked fine. But I want the web service now to run under the same application.
If I could figure out if the request was coming from My.WebSite or My.WebService, I'd be set, but I'm not sure how to do this.
Assembly.GetExecutingAssembly() returns back My.Business
Assembly.GetEntryAssembly() is null
I could check the StackTrace, but that seems sloppy and how for back would I have to go? Especially because the logging may be triggered by code in My.Business that was originally invoked from one of the other projects.
Since the web service requests end in ".asmx", the following concept works, but it just doesn't feel right.
return HttpContext.Current.Request.Path.IndexOf(".asmx") >= 0 ? "My.WebService" : "My.WebSite";
Thanks!
You should be able to use Assembly.GetCallingAssembly():
return Assembly.GetCallingAssembly().FullName;
This will return the assembly that invoked the current executing method, so you can capture whoever is calling into your My.Business assembly that way.
With that said, I tend to agree with the comment above by Meirion Hughes. You might like to consider passing in any info that is required to your logging class, especially if it is likely to be used across more applications in the future.
this.GetType().Assembly.FullName will give you the name of the assembly name for the current class.

Does ASP.Net MVC4 Cache References?

I ran into an issue today that is making me pull my hair out.
I've created a WCF service which is fairly simple as it only exposes two operations and no data contracts. This WCF service sits on top of a business logic layer. Inside this business logic layer is a dll which exposes some contracts (just plain interfaces).
I've also created two test clients for the service. One is a console client and the other is a MVC4 application. Both reference the same endpoints and they both reference, through a project reference, the contract dll.
Now, all is fine until I change the contract by adding or removing a method, or even changing the signature of an existing method. At that point my MVC4 app blows and throws all over the place. Keep in mind that I'm not changing the WCF contract, just some internal contracts.
The reason is that inside of the business logic layer I am initializing my AutoMapper profiles via a static constructor. Inside this static constructor I basically get all the assemblies of the current domain and iterate through them looking for objects that implement IProfile. It's when I start trying to get types out of one of the dlls that reference the contracts dll that I get a fatal exception: System.TypeLoadException.
Now, the console client behaves just fine. Again, referencing the same dll's through a project reference. I can change that contracts dll all day long and it's just happy as a lark, but MVC4 blows chunks. If I go back and make the interface exactly like it was before MVC4 is happy.
I noticed that the path to the assembly that was failing to load is in the Temporary ASP.Net files location. I blasted that entire directory and still no luck.
I can supply code, but it might be better if I gave you a dependency graph. There's already about 5k lines of code in the BLL.
Thanks in advance.

Can anyone suggest some good links about ASP.net based n-tier architecture

In my Visual Studio solution I m having following types of project:
Class Library - BusinessLogicLayer
(I m in doubt how to seperate functionality in BLL)
Class Library - DataAccessLayer
(I m in doubt how to seperate functioanlity in DAL)
Class Library - DataModels
(Contains various models like User,TimeTable,Address, etc.)
WCF Service App - To create common WCF service which can be consumed from jQuery(Web App) and WPF App
ASP.net WebForms Project - Web Pages
WPF Project - Windows application for same (As it is the requirement)
Setup project - Septup project to create installer for Windows app
UnitTest project - Project to make NUnit basd test cases
Can u please tell me whether or not I m going right way?
This is my first n-tier based application.
I m actually not clear to seperate functionality in layers even in my very first screen that is login screen.
It could be like this way from code behind file login.aspx.cs in OnClick_submit event I should create instance of UserBLL class and then I should call obj.validate(username,password) which returns a model of UserInfo. While that BLL class should itself call UserDB.Validate(username,password) method which returns model back to PersonBLL class.
If I use this scenario then every operation needs a seperate db conenction.
I also want to asks whether or not creating applications in this layered approach results in any extra memory consumption.
Please explain the scenario to me if you are familiar with this.
I don't know about others but I find working code to be a far better way of getting a handle on best practices. Therefore , I'd strongly recommend downloading the Patterns and Practices Data Access drop on Codeplex. It's a little old now but will provide you with a comprehensive reference sample for a Web (albeit MVC), WPF and tiered Services application.

Using Controllers without the entire MVC Framework

I'm in the process of trying out a few things with MVC whilst designing a system and wanted to try and see if I could use the concept of Controllers outside of the MVC framework. When I say outside, I mean within my own C# service as opposed to a web-site.
I started a simple console application to test the theory and it was simple enough to change the profile to a non-client profile, add in System.Web.Mvc, create a controller and have it return a JsonResult. The ease of which this got set up pleased me as that is half the work done if I want a service to respond with JSON.
The next step is to set up a Http Server class, and I would love it if I could leverage the other part of the framework which will map incoming requests to my controllers. Unfortunately, this is the part where I am lost and I have no idea what code goes on behind to arrive at a particular controller's function with the parameters all in place.
Has anyone got an idea on how to accomplish this, or a resource to look at?
In short: I'd like to leverage the use of Controllers in my own service, running it's own HTTP Server.
You can use the design pattern without using the framework - what I mean is, you can apply the model view controller pattern wherever you believe it solves the problem - if you think that you can replace "view" with "service", you could apply some of the concepts...
http://msdn.microsoft.com/en-us/library/ff649643.aspx
However, there are other patterns that may lend themselves better to services, although if we are talking specifically about a JSON service, then just using the ASP.NET MVC framework as it is would work well (rather than trying to re-write it).
Are you not trying to reinvent the wheel?
If returning JSON is one of your main purpose then WCF fulfills your need. Having WCF with you you are free to host it in IIS. This serves your second purpose having its own HTTP server.
You are trying to achieve some kind of routing where based on URL your different actions will be called. Isn't it similar to having a WCF service with different methods and client is calling each of them with different URL?
Trying controller concept in a non web application seems to be innovative, however in your case it looks like over-engineering.
The basic MVC pattern isn't all the difficult to replicate. I would seriously consider writing your own, rather than trying to shoehorn the MVC classes into your app.
Simon
If it helps you, the entire ASP.Net MVC Framework is open source, you can download it all from http://aspnet.codeplex.com/ . You can use the libraries here to view how the Framework is doing things behind the scenes and adapt things for your own use as appropriate.

Categories