当运行Fiddlercore作为Windows服务(使用C#服务模板)时,它似乎在下载网页的前50-100字节后退出。这通常足以获得页面的标题和一些标题HTML,但不多了。
我已经黑了'能够让服务在控制台模式下运行(而不是作为服务),而在这种模式下,Fiddler完美运行!
假设这可能与权限有关,我将Windows服务更改为在我的帐户下运行而不是“本地系统”,但这不起作用。
可能是什么原因?我不知道如何尝试调试此问题!
更新:这是基本代码:
Program.cs的
namespace router
{
static class Program
{
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new router()
};
if (!Environment.UserInteractive)
{
ServiceBase.Run(ServicesToRun);
}
else
{
RunInteractive(ServicesToRun);
}
}
static void RunInteractive(ServiceBase[] servicesToRun)
{
Console.WriteLine("Services running in interactive mode.");
Console.WriteLine();
MethodInfo onStartMethod = typeof(ServiceBase).GetMethod("OnStart",
BindingFlags.Instance | BindingFlags.NonPublic);
foreach (ServiceBase service in servicesToRun)
{
Console.Write("Starting {0}...", service.ServiceName);
Console.WriteLine();
onStartMethod.Invoke(service, new object[] { new string[] { } });
Console.Write("Started");
}
Console.WriteLine(
"Press any key to stop the services and end the process...");
Console.ReadKey();
Console.WriteLine();
MethodInfo onStopMethod = typeof(ServiceBase).GetMethod("OnStop",
BindingFlags.Instance | BindingFlags.NonPublic);
foreach (ServiceBase service in servicesToRun)
{
Console.Write("Stopping {0}...", service.ServiceName);
onStopMethod.Invoke(service, null);
Console.WriteLine("Stopped");
}
Console.WriteLine("All services stopped.");
// Keep the console alive for a second to allow the user to see the message.
Thread.Sleep(1000);
}
}
}
Service1.cs
namespace router
{
public partial class router : ServiceBase
{
public router()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
ProxyUtils.Start();
}
protected override void OnStop()
{
ProxyUtils.stopProxy();
}
}
}
ProxyExtension.cs
namespace ProxyExtension
{
public static class ProxyUtils
{
public static void Start()
{
startProxy();
}
public static void startProxy()
{
try
{
List<Fiddler.Session> oAllSessions = new List<Fiddler.Session>();
// Allow certificate errors from websites
Fiddler.CONFIG.IgnoreServerCertErrors = true;
// Create root certificate
CertMaker.createRootCert();
setMachineTrust(CertMaker.GetRootCertificate());
// Switch off system proxy
FiddlerCoreStartupFlags oFCSF = FiddlerCoreStartupFlags.Default;
oFCSF = (oFCSF & ~FiddlerCoreStartupFlags.RegisterAsSystemProxy);
// start proxy
Fiddler.FiddlerApplication.Startup(8080,oFCSF);
}
catch (Exception e)
{
Console.WriteLine("Error starting proxy: " + e);
}
}