asp.net core starts up ok, but all Http requests fail to run - entity-framework

Recently I started a new Asp.Net core application 1.0, and copied some existing code across from another project. After adding a considerable amount of code, and getting it to compile, I found that starting the application, appeared to start up, but when it tried to hit the Home controller to get the start page of the application, the browser reported it could NOT reach the web page. Reported a This site can’t be reached message (as if the web application was not running). This was very frustrating as the app used to work fine before I added all this extra code.
I ended up having to go back and start a brand new application (in the same project), and add components back into the project one at a time, till i found the thing that had caused this issue. A frustrating day passed where I could not get any errors from the server at all regarding why it failed to find the web page.
After a lot of menial work and cursing, I eventually tracked down the issue.
The issue was that I had added some support to do the database seeding as part of the Configure method of the Startup class. I had made this a Async Static Method, and called the method using an await inside the Configure method. Naturally I had to make the configure method Async which I did.
The reasons for adding these awaits, were so I could use Async calls within my DatabaseSeed method call
public class Startup
{
...
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
await DbExtensions.EnsureSeedData(app.ApplicationServices);
}
...
}
}
public static class DbExtensions
{
public static async Task EnsureSeedData(IServiceProvider serviceProvider)
{
using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var context = serviceScope.ServiceProvider.GetService<ApplicationDbContext>();
var auditService = serviceScope.ServiceProvider.GetService<AuditService>();
....
}
...
}
WARNING: DO NOT use the code above as an example of what to do.
So this all compiled fine and the application started up as per normal. But like i stated above, No Http calls would find the web application
So I found out that due to the await call in the configure method (which was also marked as async now), this caused the application to be in a ghost state, and not responding to any routing calls.
My question to anyone that can answer, is why the routed calls didn't register anywhere as an issue, when it failed to access the Web application?
Note I couldn't even get a debug breakpoint to be hit in any controller code.

Related

Prism - Registering a shared service

Sorry for asking such a basic question but I am stucking and trying to find what I could have gotten wrong.
How do I register a service in my shared code (both IService and Service files are in the shared code base)?
Should I use a singleton or a instance? And what is the code for it because that isn't clear to me. And couldn't find the awnser online, and here the code for register isn't given.
The service is a database service if that matters.
I tried:
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//services
containerRegistry.Register<IDbItemService, DbItemService>();
Debug.WriteLine("registered app");
}
But when calling putting this code in the constructor of my viewmodel:
IDbItemService dbItemService)
The app fails with a NSInconsistency error when run on iphone, the error says :
Application windows are expected to have a root view controller at the end of application launch
, which probably comes because the contructor can't find the service.
EDIT: The constuctor of the service also has a 'service' for the platform specific code.
Thank you
Edit2:
Yes, I see now that I have register that must be because I also tried that function and copied it. I tried both Register and Registersingleton but both still result in my app failing.
Second the service is a shared implementation, I was trying to so that with "(both IService and Service files are in the shared code base)".
Third I don't get any information on the exception I just ran the code and it just stops and gave me this error:
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch
Native stack trace:
Futhermore I am trying to implement a database following this github example. I did some more debugging and the code crashes after this line in the IncidentService located in the shared project from the example: _platformDb.Connection.CreateTableAsync<Incident>().Wait();
I am sorry for not clearly stating what the problem is, because honestly I also don't really know. So if you maybe have an example for how to implement a database in xamarin forms just throw it my way.

GWT activities and places. External link always start default place

I have lost all the morning searching for this problem on internet and nobody seems to face this problem.
My GWT application navigate very well. But as a logic requirement on my application it generates an email with a link to my application. The link is something like this:
http://server#place:token
Well, it navigate always to the same DefaultPlace i declare on initialization.
I have write a lot of logs in the client side. And it ignores completely the request. Even if i type this url in the browser, it loads default place.
My application navigates very well between places internally but now i realize that it happens not only with one particular place, but any place.
Could some one help me to realize what would be the problem. I could write the code if any want to see.
This is my PlacehistoryMapper:
#WithTokenizers({DefaultPlace.Tokenizer.class,
AuthenticationPlace.Tokenizer.class,
ProcessSnCallbackPlace.Tokenizer.class,
GatherUserInfoPlace.Tokenizer.class,
LoadProfilePlace.Tokenizer.class,
RegisterPlace.Tokenizer.class})
public interface AppPlacesHistoryMapper extends PlaceHistoryMapper
}
This is my ActivityMapper in getActivity override:
#Override
public Activity getActivity(Place place) {
Provider provider = getProvider(place);
if (provider == null) {
browserUtils.log("Error: " + place.getClass().getCanonicalName() + " Place is not mapped.");
return null;
}
return (Activity) provider.get();
}
And all activities all injected by GIN and works fine. But always when debug the default place is the only i see in those line. However if i change the place by goTo it works fine.
Thanks in advance.
Cheers
Albert.

Enabling EJB Injection into Vaadin 7 UI via Usage of Vaadin-CDI-Integration Addon

I wasn't able to successfully integrate the official Vaadin-CDI-Integration-Addon, since after finishing the official integration instructions, the following Exception was thrown in case I reloaded the already published URL localhost:8080/App/?restartApplication.
javax.servlet.ServletException: com.vaadin.server.ServiceException:
java.lang.IllegalStateException: UI id has already been defined
The following little workaround is a tested, working solution, which completes the official instructions.
You have to work off the following steps to successfully integrate the official CDI-Integration-Addon into your Vaadin project.
Do exactly as stated in the official how-to.
Remove the ?restartApplication parameter from the URL. This avoids the Exception.
Inject the EJB as shown in the listing below.
Keep in mind to restart your application manually if necessary!
#CDIUI
public class ExampleCDIUI extends UI {
#Inject
MyLocalBeanInterface myBean;
#Override
public void init(VaadinRequest request) {
Label label = new Label("Hello Vaadin user");
setContent(label);
// myBean should be accessible now.
}
}
That's it. I hope this helps :-)

Generation of .svc-files on IIS fails when using custom RIAServices.T4 code generation

I have a Silverlight application that uses a custom DomainContextGenerator and a custom EntityGenerator:
[DomainServiceClientCodeGenerator("MainCodeGenerator", "C#")]
public class HrCodeGenerator : CSharpClientCodeGenerator
{
protected override EntityGenerator EntityGenerator
{
get { return new HrEntityGenerator(); }
}
protected override DomainContextGenerator DomainContextGenerator
{
get { return new HrDomainContextGenerator(); }
}
}
This class and the referenced generators are contained in a class library referenced by the Host-project of the Silverlight application.
When starting the application in VisualStudio 2012 everything works fine and when I open http://localhost:12345/My-Namespace-MyService.svc in a browser I can see the landing page of the service. When deploying the application to the IIS however the on-the-fly-generation of the .svc-files fails and when opening http://dev.example.com/My-Namespace-MyService.svc I just receive a HTTP 404.
After removing the HrCodeGenerator-class from the project (removing the DomainServiceClientCodeGeneratorAttribute won't do the trick), everything works fine.
Do you have any hint on why it behaves that way and what I can do to prevent that from happening?
I finally solved the issue.
The classes responsible for the client code generation were located in the same library as the services itself. I moved these classes to the web-application project that gets deployed to the server.
I still don't understand how code that gets executed at compile time only and only affects the client side of the application can possibly influence the runtime behavior of the server side of the application. I also don't understand why moving the components to another project fixed the problem.
But as a colleague of mine states: "Sometimes engineering is indistinguishable from magic..."

Create a GWT RPC Service

I’m trying to create a backend for a homepage with GWT. I created a Google Web Application in Eclipse without sample code and now I would like to add the service, but the developer Google guide doesn’t help me. I’m not sure, where to add the interface and how it exactly works.
If I understand the google documentation correctly, I have to add a module and an entry point class, is that correct? It would be great if you could give me some tips and help how to create a rpc service.
If you create a new GWT project in the Eclipse "New Project" wizard, with "Generate project sample code" checked, it will include a fully functioning RPC service with a sample method, which you can then adapt or copy according to your needs.
Out of memory, don't have eclipse in front of me.
First do create a test project with generated testcode, you can delete it afterward.
Yes you will have to add a module.
Create in client the two interfaces for the async calls, inherit it on server side.
Hope I understood your question right.
I'm not sure what would help you the most. Google developer guide was enough for me (at least when I started using it on version 1.6) to create RPC services for my GWT application.
General APP
Module: is the .gwt.xml file. Yes, you'll need it. The GWT compiler will find it automagically and try to compile all the GWT code (the <source> element will tell which subpackage contains Java code that will be converted to JS). It will tell also which class implements the EntryPoint interface. The onModuleLoad will be the code executed when javascript runs in the client page.
RPC
Well, you should first try UI things and only then, when you're confident enough, try the server thing. Anyway the scheme is:
interface MyService extends RemoteService {
List<String> doSomething(String sample, int other);
}
#RemoteServiceRelativePath("../path/to/servlet") // see later
intercace MyServiceAsync {
void doSomething(String sample, int other, AsyncCallback<List<String>> callback);
}
These are the interfaces. Later is the async one. That's what you'll use from client side. Always calling and passing an implementation of AsyncCallback which will receive (sometime later, you don't know when) the result.
First interface is the syncrhonous one. That is what you need to implement on server. You must inherit from RemoteServiceServlet class (it is an implementation of servlet that already does all the values handling), and implement your interface. GWT code does the rest (almost).
public class ServiceImpl extends RemoteServiceServlet implements MyService
{
// implement the method normally
}
From client you'll need to create the service proxy:
private static MyServiceAsync MY_SERVICE = GWT.create(MyService.class);
Yes. I know it's weird how GWT knows MyserviceAsync and MyService work together. Don't worry about that. It works :)
Just use the service like this:
MY_SERVICE.doSomething("value", 111, new AsyncCallback<List<String>>() {
// note that this code executes some time in the future when response from server is back
public void onSuccess(List<String> result) {
Window.alert("Server answered with " + result.size() + " elements!");
}
public void onFailure(Throwable t) {
Window.alert("Server failed: " + t.getMessage());
}
}
Path to server
You'll have to configure your app to make that servlet implementation listen to URL indicated in #RemoteServiceRelativePath. That's the way client knows where to make the request, and the server knows which servlet attends that request. I'd suggest using:
../my-service.gwt as relative path (GWT module gets published in <ROOT>/module_name
and
configuring your web app to use the servlet for /my-service.gwt
But it's entirely upon your preferences :)
Anyway I think Google tutorials are the best. So please copy&paste. Try&modify until you get to understand the whole thing.