如何从IIS托管的WCF服务启动进程? [英] How to start a process from an IIS hosted WCF service?

查看:102
本文介绍了如何从IIS托管的WCF服务启动进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从WCF服务端的Intranet客户端运行一个进程.在我的情况下,客户端要求服务器在提供的凭据下在服务器的计算机上创建新进程.WCF服务托管在IIS 7.5上,我使用此代码启动进程

I would like to run a process from an intranet client on the WCF service side. In my case a client asks a server to create a new process on the server's machine under the provided credentials. WCF service is hosted on IIS 7.5 and I start a process using this code

var processInfo = new ProcessStartInfo("C:\\Windows\\System32\\notepad.exe")
{
    UserName = "some user",
    Password = MakeSecureString("some password"),
    UseShellExecute = false,
    LoadUserProfile = true
};

Process process = Process.Start(processInfo);

如果我将WCF服务作为以管理员用户身份运行的自托管控制台应用程序托管,并且看到记事本在另一个用户下启动,则此代码有效.毫无例外,它在IIS上失败,但是进程立即终止

This code works if I host WCF service as a self-hosted console application running under admin user and I see the notepad started under another user. It fails on IIS with no exception, but process is immediately terminated

process.HasExited = true;
process.ExitCode = -1073741502;

在IIS上,WCF应用程序在具有管理员权限的用户下运行,并且已在web.config中定义了完全信任.我不能使用自托管应用程序,因为它不支持简单的连续交付(例如带有IIS Web场的WebDeploy).

On IIS WCF application is running under the user with admin rights and has got full trust defined in web.config. I cannot use self hosted application as it doesn't support easy continuous delivery (like WebDeploy with IIS web farms).

问::如何从IIS上托管的WCF服务在服务器端启动进程?

Q: How can I start a process on a server side from WCF service hosted on IIS?


我偶然发现了这个帖子,存在类似问题我尝试了所有方法,包括使用CreateProcessWithLogonW和CreateProcessAsUser进行Process.Start和P/Invoke的所有可能的变体,我还尝试向用户授予其他权限.不能使用与该人发布的错误消息相同的错误消息.


I stumbled upon this post, with similar issues and I tried all the methods there, including all possible variations for Process.Start and P/Invoke with CreateProcessWithLogonW and CreateProcessAsUser I also tried granting additional permissions to users. Non of this would work with the error messages identical to the ones the guy had posted.

推荐答案

Oleksii,重点是,如果您在控制台应用程序中托管WCF服务,则存在一个Windows会话(已登录用户并已加载Windows资源管理器)该用户,便会打开并显示该用户的记事本,因此您可以在用户界面中看到它.

Oleksii, the point is that if you host the WCF service in a console application, there is a windows session (a user logged in and Windows Explorer loaded) for that user and the notepad is opened and shown for that user, so you see it in the UI.

在作为服务器的IIS中托管WCF服务时,IIS要求并且不允许用户交互,并且如果没有用户登录也可以工作;在这种情况下,没有UI来承载您的记事本或其他启用UI的应用程序,您可以执行详细处理或其他批处理作业的过程,但不能呈现Windows UI应用程序,因为未为您加载Windows资源管理器,并且无处可放呈现流程的用户界面.

when you host your WCF service in IIS, being a server, IIS requires and allows no user interaction and works also if no user is logged in; in that context there is no UI to host your notepad or other UI enabled applications, you could execute a process for elaboration or other batch jobs but not render a windows UI application, because Windows Explorer is not loaded for you and there is no place to render your process's UI.

这篇关于如何从IIS托管的WCF服务启动进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆