我已經引用了一些關於如何在stackoverflow上執行此操作的提及。WebService不運行exe
我試着從以下基準測試代碼:
https://www.dotnetperls.com/process
How to run .exe file by my Webservice?
版本:框架3.5
VisualStudio2010
,當我跑我下面的代碼在瀏覽器中,我看到要點擊的項目符號。當我點擊它時沒有任何反應。我的exe只是找到一個xml文件並從中創建一個新文件。我想用一個web服務來運行exe。我的代碼中是否存在某些內容?還有其他版本,我看到有更多的代碼,但我嘗試過,仍然沒有運氣[檢查我的鏈接]
這是我的第一個webservice,所以我正在學習,因爲我去。
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://localhost/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Dim File As String
<WebMethod()> _
Public Sub runExe()
Dim exe = "C:\WindowsApplication1\bin\Debug\WindowsApplication1.exe"
'Dim file = "C:\Test\test.xml"
Dim startInfo As New ProcessStartInfo()
startInfo.FileName = exe
'startInfo.Arguments = file
Process.Start(startInfo)
'REFERENCE: https://www.dotnetperls.com/process
End Sub
我也試過calling .exe from another .exe to run a webservice使用
ThreadPool.QueueUserWorkItem(Sub() Process.Start("C:\WindowsApplication1\bin\Debug\WindowsApplication1.exe"))
但EXE沒有跑又名我沒有看到在exe文件將其發送到文件夾路徑創建新的文件。
也試過:
Dim processInfo = New ProcessStartInfo(exe)
Dim process__1 = Process.Start(ProcessInfo)
process__1.WaitForExit(5000)
Dim exitCode = process__1.ExitCode
process__1.Close()
Return
什麼都沒有發生
UPDATE:
沒想到使用輸出測試,以找出我的問題。我用下面的:
While Not process__1.StandardOutput.EndOfStream
Dim line As String = process__1.StandardOutput.ReadLine()
End While
'WindowsApplication1.vshost.exe'?你不是想要運行'WindowsApplication1.exe'嗎?另外,你可以做一些調試來確認應用程序沒有被執行嗎?也許在應用程序中包含一些調試輸出?或者當你在這裏調用它時讀取進程的輸出?看起來很有可能是因爲你沒有捕獲或者你的測試沒有按照你自己的想法去做,而是因爲一個很好的理由而失敗。 – David
是的,這是錯字。我會研究創建過程的輸出。 @David – narue1992
此外,雖然這可能是顯而易見的,但它經常值得提問,因爲很多人都掛在這上面...您是否期望這個應用程序在* server *或* client *上運行? – David