简体   繁体   English

IIS上的Web服务

[英]Webservice on IIS

I have a webservice and a webform. 我有一个网络服务和一个网络表单。 A button invokes the webservice which reads a given process name from pid. 按钮调用Web服务,该服务从pid读取给定的进程名称。 This works fine in VS2008 but when I publish my project I dont get the name? 这在VS2008中可以正常工作,但是当我发布项目时却没有名称? How can I configure IIS to allow me to do so? 如何配置IIS以允许我这样做? or is there an alternative way ie wcf or wwf? 还是有另一种方式,即WCF或WWF?

Edit: 编辑:

using System.Diagnostics;

[WebMethod]
        public string GetProcessName()
        {
            Process Process = Process.GetProcessById(1428);
            string ProcessTitle = Process.MainWindowTitle;
            return ProcessTitle;
        }

I used tasklist.exe /v to get the pid of a process which has a window title. 我使用tasklist.exe / v获取具有窗口标题的进程的pid。

Given your code: 给定您的代码:

  • how do you know there's a process with PID = 1428 ?? 您怎么知道有一个PID = 1428的进程?
  • what happens if that process doesn't exist? 如果该过程不存在会怎样?

If you check out this line of code: 如果您查看以下代码行:

Process process = Process.GetProcessById(1428);

will return NULL , and then you grab the .MainWindowTitle from...... NULL..... that's guaranteed to cause an exception..... 将返回NULL ,然后从.MainWindowTitle抓取.MainWindowTitle …… 保证会导致异常。

using System.Diagnostics;

[WebMethod]
public string GetProcessName()
{
   string processTitle = string.Empty;

   Process process = Process.GetProcessById(1428);

   if(process != null)
   {     
      processTitle = process.MainWindowTitle;
   }

   return processTitle;
}

And even so - again: how do you know a process with ID = 1428 exists?? 甚至如此-再次:您如何知道ID = 1428的进程存在?

I can't believe that when I deployed my project to Abyss web server it works like a charm. 我不敢相信,当我将项目部署到Abyss Web服务器时,它就像一个魅力。 Thanks all anyways. 还是谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM