I have the following problem,
I wish to install an application of mine as a service on the system.
My class inherits from System.Configuration.Install.Installer. The problem starts when in the constructor of that class I try to get the parameters of Context property, then I get the following exception:
Unable to create an instance of (my class name that inherits from installer) installer type.
When I printed out the Context property, I saw it was null (and it throws the exception when trying to reach the context property) in the constructor.
Same code works fine on 2003 and installation is finished successfuly, but here it fails.
Move your code from constructor to Install, if possible. A common usage of Installer would be:
using ( TransactedInstaller transactedInstaller = new TransactedInstaller() )
{
transactedInstaller.Installers.Add(myInstaller);
transactedInstaller.Context = new InstallContext(null, null);
transactedInstaller.Install(new System.Collections.Hashtable());
}
That's why Context is null in the constructor.
Related
I am getting error FabricServiceNotFoundException: Service does not exist. and I can't figure out why. The service name I am creating is exactly what it is deployed in my cluster.
This is the code where I create my service:
return ServiceProxy.Create<ICheckoutService>(
new Uri("fabric:/ECommerce/ECommerce.CheckoutService"),
new ServicePartitionKey(0));
This is the explorer view. The name of the service matches my code. I'm doing it with other services with no problem.
I tried a complete restart but I got the same error:
Deleted application from the cluster
Unprovisioned type from the cluster
Restarted the cluster
Restarted Visual Studio
Rebuild and deployed application
Update
After testing around I found out that the error occurs depending on the order on which I call services through my API methods.
If I deploy the application and call methods checkout and get basket they give "Service not found" error.
However, if I call other methods first that perform some change (POST), then it works... weird right? This is my repo to help take a look at the code.
https://github.com/epomatti/azure-servicefabric-productcatalog
With help of #maf748 I turned on "Break When Thrown" configuration for all CLR exceptions, and I discovered that the actual exception was not "Service does not exist".
In my case, I left the following auto-generated method for an Actor service, which was setting my state in a wrong state, and it was later failing in my own code.
All I needed to do was to remove this method that Visual Studio created from my method and it worked properly.
/// <summary>
/// This method is called whenever an actor is activated.
/// An actor is activated the first time any of its methods are invoked.
/// </summary>
protected override Task OnActivateAsync()
{
ActorEventSource.Current.ActorMessage(this, "Actor activated.");
// The StateManager is this actor's private state store.
// Data stored in the StateManager will be replicated for high-availability for actors that use volatile or persisted state storage.
// Any serializable object can be saved in the StateManager.
// For more information, see https://aka.ms/servicefabricactorsstateserialization
return this.StateManager.TryAddStateAsync("count", 0);
}
I've created the WCF service and some simple WPF application consuming it. When I'm running the project from within Visual Studio, the WCF Test Client opens and the application works just fine, method defined in service work.
But I need to host this WCF service in a Windows Service. I've followed this, installed the services using Installutil.exe and the ran the service. Everything went fine, it's working.
Yet, when I'm trying to open the executable file with WPF application directly from the debug folder of the app, I'm getting this error:
zad8. has stopped working
After choosing the option to debug it with new instance of VS I get
XamlParseException occured in PresentationFramework.dll
The stack trace shows something like:
connection can't be started, because the target computer is actively refusing it
Do you have any idea what could go wrong?
Fortunately, I've managed to come up with solution. I think I should post it, maybe one day it will help somebody:)
I actually did two mistakes, but one of them was unfortunately caused by the mentioned tutorial (here) in connection with my temporary blackout.
In step 5, point 8 of this tutorial, there's an example of overriding OnStart() method:
protected override void OnStart(string[] args)
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(Service1));
myServiceHost.Open();
}
Beware, that Service1 is ambiguous in this context, because it's name of the Windows Service project class as well as the name of WCF Service class. It should be written with fully qualified name (here it is WcfServiceLibrary1.Service1). In my case, the service name was different, and I just put the Service1 in there in a hurry. Anyway..
In case, someone has it all behind and still encounters the same problem (with app stopped working), I think that you should try open the project in Visual Studio and try to debug the client consuming application as a new instance (right click on the project-> Debug -> Start as new instance...).
It might seem trivial, but when u hit F5 or Ctrl+F5 then even if u have only those project set as startup project, VS will host it's client anyway. In my case it did matter, because I needed to use isolation storage file. And as it was kept on the service side, then I had this file created in IIS server created by VS. Somehow, my method of creating such file had set FileMode.Open() and it was causing the crush, because in Windows Service it didn't exist and the new one couldn't be created and that was neccessary to run it correctly.
What's more it just showed me that this question couldn't be answered properly, cause the data I've provided was not enough and it was delicate.
Cheers:)
I have added a Service Reference to my Windows Phone 8 Project and it is showing in the Service Reference folder.
When I try to create an instance of the service, such as:
var service = new MobileService();
It doesn't recognise what MobileService is. Same goes for when I try doing using MobileService; at the top of the class.
Where am I going horribly wrong?
The class is probably called MobileServiceClient. Click the show all files option for your project and you can view the generated code of the service references.
Upon installation of a Windows Service, an application is using a custom action to set the ServiceName and DisplayName of that service according to whatever the user enters into an install dialog text box.
In testing this application it works fine for installation but when I try to uninstall the service I get an Error 1001. Service does not exist.
which is ultimately not true because I can run it. So my present thinking is that i need to somehow access the custom name of the service and feed that to the uninstaller. I would have thought this was all GUID based and that the name would become largely irrelevant re: uninstall but it would seem not to be the case.
So how to do I resolve this problem?
I will assume that your are using an Installer derived class together with a ServiceInstaller instance.
I do something similar in a project. The service name is stored inside a text file (this is just an option, but for me it's there for automatic deployment purposes). You can store it anywhere (registry, etc).
So you should persist somewhere the custom service name configured during the install phase.
So, I have my Installer class:
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
And in it's constructor, I do:
_process = new ServiceProcessInstaller { Account = ServiceAccount.LocalSystem };
_service = new ServiceInstaller { ServiceName = ServiceNameReader.GetServiceName(), StartType = ServiceStartMode.Automatic };
Installers.Add(_process);
Installers.Add(_service);
Notice the ServiceNameReader.GetServiceName() function. This custom function gets the service name from the file.
The Installer class is instantiated and called during uninstallation too. So if you do something like this, to load the actual service name dynamically from somewhere, you will be able to uninstall it successfully.
I'm connecting to a web service hosted by a third-party provider. I've added a service reference in my project to the web service, VS has generated all the references and classes needed.
I'm connecting with this piece of code (client name and methods anonymized):
using (var client = new Client())
{
try
{
client.Open();
var response = client.Method(...);
return response.Status;
}
catch (SoapException ex)
{
throw CreateServiceException(ex);
}
finally
{
client.Close();
}
}
When reaching the client.Open(), I get an exception with this message:
The top XML element '_return' from
namespace '' references distinct types
System.Boolean and
Service.Status.
Use XML attributes to specify another
XML name or namespace for the element
or types.
In reference.cs, I can see that the "_return" variable is decorated with
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
Is there a problem with the wsdl, the generated service reference or in my code?
Update: Generating the service as an old school Web Service solves the problem. I've marked Sixto's answer as accepted for now, but I'm still curious what could've caused the problem and if any parameters to the service generator could solve the original problem.
If you were able to create a service reference then the WSDL is valid. The exception message is saying you have namespace/type ambiguity problem with _return. The generated code is probably using it in some context as a boolean and in another context as a Service.Status type.
I don’t call the ClientBase.Open method before invoking a service method because I’ve never seen the need for it. I do always call the Close & Abort methods as appropriate. The Open method basically just changes the state of the client to no longer be configurable. I’m not sure how that would trigger code in the generated class since it is an inherited method. I’d try just removing that line and see if you get the same exception. Otherwise, if you haven’t already done so, search the generated code for all the places _return is used and see if you can manually sort-out the appropriate type. You may need different names for each context.
Another way to troubleshoot the WSDL is to create a Web Reference (assuming it’s an HTTP based service) and see if the generate code works as expected. If it does work, go with the ASMX client unless you have a need for WCF proxy capabilities.