void GetNTP() { DeviceClient client = null; try { client = new DeviceClient(new HttpBinding(new IChannelController[] { _listener }), new EndpointAddress(tbAddress.Text)); try { NTPInformation ntp = client.GetNTP(); } catch (FaultException exc) { BeginInvoke(new Action(() => { WriteLine("Fault!", System.Drawing.Color.BlueViolet); WriteLine(exc.Code.Name, System.Drawing.Color.Green); System.ServiceModel.FaultCode code = exc.Code.SubCode; string offset = " "; while (code != null) { WriteLine(string.Format("{0}Subcode: {1}", offset, code.Name), System.Drawing.Color.Green); offset = " " + offset; code = code.SubCode; } })); } BeginInvoke(new Action(() => WriteLine("OK"))); } catch (Exception exc) { if (client != null) { client.Abort(); } BeginInvoke(new Action(() => ReportError(exc))); //throw; } finally { StopAnimation(); } }
static void Main(string[] args) { Console.Out.WriteLine("Testing custom Http From Imported Files Generated By SvcUtil."); DeviceClient client = new DeviceClient(new CustomHttpBinding(true), new EndpointAddress("http://192.168.3.144:80/onvif/device_service")); //DeviceClient client = new DeviceClient(new CustomHttpBinding(true), new EndpointAddress("http://localhost:27468/Dut.asmx")); try { HostnameInformation info = client.GetHostname(); Console.WriteLine("HostnameInformation.Name: {0}", info.Name); Console.WriteLine("---------------------------------------------------"); try { NTPInformation ntp = client.GetNTP(); Console.WriteLine("NTPInformation.FromDHCP: {0}", ntp.FromDHCP); } catch (Exception exc) { Console.WriteLine(exc.Message); } Console.WriteLine("OK"); //client.BeginGetHostname(new AsyncCallback(GetHostnameCallback), client); } catch (Exception exc) { client.Abort(); Console.WriteLine(exc.Message); //throw; } Console.Out.WriteLine("Press <ENTER> to complete test."); Console.In.ReadLine(); }