Ciao a tutti,
sono molto novello sul C# e sto creando il mio primo servizio, onestamente ho preso un po' di riferimenti dalla libreria di winscp e sto provando a dilttarmi per veder se riesco a far funzionare il tutto.
Allora il Codice Funziona perfettamente, e quindi, mi direte, che scrivi a fare? Bene, non mi funziona l'installazione di InstallUi.
Il messaggio si ripete
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///c:\test\FLR_ftp.APPLICATION' or one of its dependencies. The module was expected to contain an assembly manifest..
e anche se uso setup.exe
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///c:\test\setup.exe' or one of its dependencies. The module was expected to contain an assembly manifest..
ho provato come dicevano anche su internet a cambiare i framework ma niente, l'errore continua a essere lo stesso.
il mio Script l'ho suttivido con
Program.cs che contiene
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using WinSCP;
namespace WindowsService2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
}
}
poi c'è ProjectInstaller.cs a cui non ho toccano niente come da istruzioni
namespace WindowsService2
{
partial class ProjectInstaller
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
//
// serviceInstaller1
//
this.serviceInstaller1.Description = "E-invoice Service";
this.serviceInstaller1.DisplayName = "E InvoiceService";
this.serviceInstaller1.ServiceName = "Service1";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});
}
#endregion
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
}
}
infine ho terminato con il servizio Service1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using WinSCP;
namespace WindowsService2
{
partial class Service1
{
public static int MainFLR()
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "xx.pop.et",
UserName = "zip-ftp",
Password = "lalle1",
//SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
};
using (Session session = new Session())
{
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.GetFiles("/ftp/erbranch/Fatture Elettroniche Fornitori/FLR/*", @"F:\FLR\PRODUCT\Account Payable\", false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Download of {0} succeeded", transfer.FileName);
}
}
return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return 1;
}
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
#endregion
}
}
è tutto il pomeriggio che ci sto sbattendo la testa, ma niente. Avete Idee? pls