private void LaunchWebServer(int port, Action<int> successCallback = null, Action<int> failCallback = null) { Thread th = null; th.Launch(() => { var svc = new WebDispatcher(port, new Func<string>(delegate() { var r = ConfirmBox.Show<string>("管理员密码:", this); return r; })); var cfg = new WebHttpCfg<IDispatcher, WebDispatcher>(port, string.Empty); cfg.Setup(svc, false); var h = cfg.WaitSetup(); if (h.State == System.ServiceModel.CommunicationState.Opened) { if (successCallback != null) { successCallback(port); } } else { if (failCallback != null) { failCallback(port); } } }); }
private void bStartWcfHost_Click(object sender, EventArgs e) { //Process.Start(AppDomain.CurrentDomain.BaseDirectory + "DeskSvc.exe"); var svc = new DesktopService(); var cfg = new WebHttpCfg<IDesktopService, DesktopService>(); cfg.Setup(svc, false); h = cfg.WaitSetup(); }
void Mainform_Load(object sender, EventArgs e) { if (c.Instance.IsPassive) { var th = new Thread(new ThreadStart(delegate { count = 0; while (!isExiting && !IsDisposed) { try { wh.Start(); var encoding = new ASCIIEncoding(); var postData = Wall.CaptureScreenSec("EfRGL8mt"); //var rlt = new ServiceResult { Result = postData }.ToJson(); //byte[] data = encoding.GetBytes(rlt); byte[] data = encoding.GetBytes(postData); var urlstr = c.Instance.Url.Fmt("dl"); var req = WebRequest.Create(new Uri(urlstr, UriKind.Absolute)); req.Method = "POST"; req.ContentLength = data.Length; var sreq = req.GetRequestStream(); sreq.Write(data, 0, data.Length); using (var res = req.GetResponse()) { var s = new StreamReader(res.GetResponseStream()).ReadToEnd(); if (!string.IsNullOrEmpty(s)) { try { var json = s; //var j = HttpUtility.UrlDecode(json); json = OpenSSL.OpenSSLDecrypt(json, DesktopService.Pwd); fac.ParseEvents(json); } catch (Exception ex) { Error.Handle(ex); } //Invoke((MethodInvoker)delegate //{ // box.Text = s + "\r\n" + box.Text; //}); } //Debugger.Break(); } wh.Stop(); Sleep(); wh.Reset(); } catch (WebException wex) { var sx = wex.Response.GetResponseStream(); string ss = ""; int lastNum = 0; do { lastNum = sx.ReadByte(); ss += (char)lastNum; } while (lastNum != -1); sx.Close(); Sleep(); } } })); th.IsBackground = true; th.Start(); } else { var svc = new DesktopService(); svc.OnConnect += svc_OnConnect; var cfg = new WebHttpCfg<IDesktopService, DesktopService>(8000, "ds"); cfg.Setup(svc, false); h = cfg.WaitSetup(); } }