Executable app(.exe) not running via the ASP.Net Webservice(.asmx) - .net-4.0

I want to execute a process from the ASP.Net Webservice(.asmx).
In the Webservice hosted directory, I have a executable app in "importerapp" folder of the webservice directory. My executable app is ( Named as Import.exe) is working good by double clicking.
My webservice is running with no error but the process is not executed.
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string executeProcess(RunMode mode )
{
Process process = new Process();
process.StartInfo.FileName = Server.MapPath("importerapp/Import.exe");
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.Arguments = "mode=" + (int)_runMode ;
process.Start();
process.WaitForExit();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
return("Job Submitted OK with params: "+_runMode + error
+ output +"Exit Code:"+ process.ExitCode );
}
In the browser, The output is as below.
<string xmlns="http://tempuri.org/">Job Submitted OK with
params: Exit Code:0</string>
That means, the "error" and "output" variable is null and exit code is 0 which means success.
But the processing is not doing anything, even not creating logfile( I am using nLog library).
Environment: WIndows7, IIS 7.5, .Net4.0, C#, ASP.Net
Please advise.
Thanks.
Ruhul

Job Submitted OK with params: Exit Code:0
This, according to your code, means that _runMode variable is not initiated. I think you forget to pass the parameter mode to your process

Related

Is there a way to conect the input/output of a console application to the output/input of another program

I have an application i cannot edit that reads from the console and writes to it and i want to know how i can read what the program is saying and write back commands to the program.
This is for a minecraft server where i want to read what the players are saying and run commands acoording to what is said. (the server is the application i cannot edit)
I cannot create a modification for the server, because i am using a mod that checks if there are any other modifications done to the files and fails to load if that is the case.
I wrote a simple app in c# to get started with, to redirect the I/O streams you need to start the application (in this case the server) within your own application.
First we create a new instance of the System.Diagnostics.Process class
var process = new Process();
then we specify the start info
process.StartInfo = new ProcessStartInfo
{
FileName = Console.ReadLine(), //Reads executable path from console
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false
};
then we add an event handler, in this example it's just writes the lines with a "> " prefix
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine($"> {e.Data}");
and now we can start the process by calling Process#Start()
process.Start();
and finally we can call Process#BeginOutputReadLine() without this the OutputDataReceived event will never trigger
process.BeginOutputReadLine();
To send commands you can use the process' StandardInput stream
process.StandardInput.WriteLine("command");
The fully working code with example output (tested with cmd.exe, but it's must work with MC servers)
Code:
static void Main(string[] args)
{
Console.Write("Enter executable path: ");
var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = Console.ReadLine(), //Reads executable path, for example cmd is the input
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false
};
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine($"> {e.Data}");
process.Start();
process.BeginOutputReadLine();
process.StandardInput.WriteLine("echo a");
//Prevent closing
Console.ReadKey();
}
Output:
Enter executable path: cmd
> Microsoft Windows [Version 10.0.18362.239]
> (c) 2019 Microsoft Corporation. Minden jog fenntartva.
>
> F:\VisualStudio\StackOverflow\StackOverflow\bin\Debug\netcoreapp2.1>echo a
> a
>

WCF - TargetInvocationException was unhandled

I'm trying to create WCF to sync my mobile device with my server. When i try to click sync button it throws TargetInvocationException. Below is the Sync() method.
Code
Cursor.Current = Cursors.WaitCursor;
CustomerProxy.CustomerCacheSyncService svcProxy = new CustomerProxy.CustomerCacheSyncService();
Microsoft.Synchronization.Data.ServerSyncProviderProxy syncProxy =
new Microsoft.Synchronization.Data.ServerSyncProviderProxy(svcProxy);
// Call SyncAgent.Synchronize() to initiate the synchronization process.
// Synchronization only updates the local database, not your project's data source.
CustomerCacheSyncAgent syncAgent = new CustomerCacheSyncAgent();
syncAgent.RemoteProvider = syncProxy;
/*throws error below code*/
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
// TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
customer_ConfirmationTableAdapter.Fill(testHHDataSet.Customer_Confirmation);
// Show synchronization statistics
MessageBox.Show("Changes downloaded: " + syncStats.TotalChangesDownloaded.ToString()
+ "\r\nChanges Uploaded: " + syncStats.TotalChangesUploaded.ToString());
Cursor.Current = Cursors.Default;
Thanks.
I've recreated the Web Service again and it works now. The problem was the mobile device couldnt find my local webservice. Thanks.

ClickOnce application won't accept command-line arguments

I have a VB.NET application that takes command-line arguments.
It works fine when debugging provided I turn off Visual Studio's ClickOnce security setting.
The problem occurs when I try to install the application on a computer via ClickOnce and try to run it with arguments. I get a crash when that happens (oh noes!).
There is a workaround for this issue: move the files from the latest version's publish folder to a computer's C: drive and remove the ".deploy" from the .exe. Run the application from the C: drive and it will handle arguments just fine.
Is there a better way to get this to work than the workaround I have above?
Thanks!
"Command-line arguments" only work with a ClickOnce app when it is run from a URL.
For example, this is how you should launch your application in order to attach some run-time arguments:
http://myserver/install/MyApplication.application?argument1=value1&argument2=value2
I have the following C# code that I use to parse ClickOnce activation URL's and command-line arguments alike:
public static string[] GetArguments()
{
var commandLineArgs = new List<string>();
string startupUrl = String.Empty;
if (ApplicationDeployment.IsNetworkDeployed &&
ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
// Add the EXE name at the front
commandLineArgs.Add(Environment.GetCommandLineArgs()[0]);
// Get the query portion of the URI, also decode out any escaped sequences
startupUrl = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString();
var query = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
if (!string.IsNullOrEmpty(query) && query.StartsWith("?"))
{
// Split by the ampersands, a append a "-" for use with splitting functions
string[] arguments = query.Substring(1).Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries).Select(a => String.Format("-{0}", HttpUtility.UrlDecode(a))).ToArray();
// Now add the parsed argument components
commandLineArgs.AddRange(arguments);
}
}
else
{
commandLineArgs = Environment.GetCommandLineArgs().ToList();
}
// Also tack on any activation args at the back
var activationArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
if (activationArgs != null && activationArgs.ActivationData.EmptyIfNull().Any())
{
commandLineArgs.AddRange(activationArgs.ActivationData.Where(d => d != startupUrl).Select((s, i) => String.Format("-in{1}:\"{0}\"", s, i == 0 ? String.Empty : i.ToString())));
}
return commandLineArgs.ToArray();
}
Such that my main function looks like:
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
var commandLine = GetArguments();
var args = commandLine.ParseArgs();
// Run app
}

Getting No application is associated with the specified file for this operation while executing AutoIt scripts from vb.net

I have installed AutoIt on my machine. Its working ok on one machine but same configuration and code is not working on other. Any idea what I am missing?
Following error
Could not start process Z:\test\AutoItScripts\test.au3
No application is associated with the specified file for this operation
Also autoit script successfully executes from command line. Its just getting this error while using the following code to execute
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.Verb = "runas"
objProcess.StartInfo.Arguments = Argument
objProcess.StartInfo.FileName = ProcessPath
objProcess.Start()
'Wait until it's finished
objProcess.WaitForExit()
'Exitcode as String
Console.WriteLine(objProcess.ExitCode.ToString())
objProcess.Close()
Because AutoIt3 scripts are not themselves executable, you will need to be using shellexecute.
p.UseShellExecute = true;
Process compiler = new Process();
compiler.StartInfo.FileName = sExeName;
compiler.StartInfo.Arguments = sParameters;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
Console.WriteLine(compiler.StandardOutput.ReadToEnd());

Redirecting Standard Output from a Process (msxsl.exe) to a string in VB.NET

I am writing a command line application in VB.NET. This application is calling another one, msxsl.exe, to run an XSL transform. I am using the Process class to do this:
Dim process = New Process()
process.StartInfo.FileName = "msxsl.exe"
process.StartInfo.Arguments = "base.xml test.xsl -o styled.xml"
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.StartInfo.RedirectStandardOutput = True
process.Start()
This part works great. What I want it to be able to display the output from this process to the console of my application. I have read several posts explaining this method, but it does not seem to work in this case. The output is an empty string.
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
Console.WriteLine(output)
I have verified that if I run the msxsl executable on its own (i.e. running "msxsl.exe base.xml test.xsl -o styled.xml"), it displays output on the command line. What am I doing wrong?
EDIT: I should note that the msxsl process is currently failing due to a malformed XML file. It is displaying this error message:
Error occurred while executing stylesheet 'test.xsl'.
Code: 0x800c0006
The system cannot locate the object specified.
This is exactly the type of thing I want displayed in the console of my application (or, eventually, a log file.)
This is probably because this isn't standard output it is StandardError you will want to redirect StandardError like so Process.StartInfo.RedirectStandardError = True and then read that into a string.
Dim ErrorString As String = Process.StandardError.ReadToEnd()