public static WebProxy2Usb GetProxy(DeviceCommand usb) { WebProxy2Usb proxy = null; lock (usbProxies) { proxy = (WebProxy2Usb)usbProxies[usb]; if (proxy == null) { LocalPort++; proxy = new WebProxy2Usb(usb); usbProxies[usb] = proxy; } } return(proxy); }
public override void ParseWsdl(string wsdl, string service, object device) { DeviceCommand dev = (DeviceCommand)device; lock (this) { if (Importer == null) { Importer = new WsdlImporter(dev); } } if (wsdl.EndsWith("0\r\n\r\n")) { wsdl = wsdl.Substring(0, wsdl.Length - 5); } DeviceCommand newDev = new DeviceCommand(dev); // Set the proxy server to our own application proxy in order to direct the http traffic to the USB device WebProxy2Usb usbProxy = WebProxy2Usb.GetProxy(newDev); IWebProxy webProxy = new WebProxy(usbProxy.ProxyAddress, true); string compiled = Importer.LoadWsdl(wsdl, dev); if (compiled == null) { return; } dev.Logger.Add(new Log(LogType.DotNetAssembly, compiled)); AssemblyImporter.AssemblyCommand[] webMethods = null; try { webMethods = AssemblyImporter.LoadAssembly(compiled); } catch (Exception e) { dev.Logger.Add(new Log(LogType.WEBError, e.Message)); return; } newDev.Add(new DeviceCommand.ParentCommand(service)); foreach (AssemblyImporter.AssemblyCommand method in webMethods) { try { SoapHttpClientProtocol soapMethod = (SoapHttpClientProtocol)method.Class; string url = soapMethod.Url; int pos = url.IndexOf("http://") + 7; pos = url.IndexOf("/", pos); if (pos > 0) { soapMethod.Url = usbProxy.ProxyAddress + url.Substring(pos); } newDev.Add(method); } catch (Exception e) { dev.Logger.Add(new Log(LogType.WEBError, e.Message)); } DeviceCommand.IssueChange(newDev, service + "'s Web Service Methods..."); } }