Class Servicepinger {private static readonly ILog log = Logmanager.getlogger (typeof (Servicepinger)); Public Servicepinger (String siteName, String SiteURL, String serviceurl) {if (siteName = = null) throw new ArgumentException ("SiteName can ' t be null"); if (SiteURL = = null) throw new ArgumentException ("SiteURL can ' t be null"); if (serviceurl = = null) throw new ArgumentException ("serviceurl can ' t be null"); if (Sitename.length = = 0) throw new ArgumentException ("SiteName can ' t be empty"); if (Siteurl.length = = 0) throw new ArgumentException ("SiteURL can ' t be empty"); if (Serviceurl.length = = 0) throw new ArgumentException ("serviceurl can ' t be empty"); Pingingsitename = SiteName; Pingingsiteurl = SiteURL; serviceurltoping = serviceurl; } private String PinGingsitename = string. Empty; private string Pingingsiteurl = String. Empty; private string serviceurltoping = String. Empty; private int timeoutinmilliseconds = 3000; <summary>//Does The actual pinging of the service///</summary> public void Ping ( {try {HttpWebRequest request = (HttpWebRequest) webrequest.create (serviceur ltoping); Request. Method = "POST"; Request. ContentType = "Text/xml"; Request. Timeout = Timeoutinmilliseconds; Request. Credentials = credentialcache.defaultnetworkcredentials; Stream stream = (stream) request. GetRequestStream (); using (XmlTextWriter writer = new XmlTextWriter (stream, Encoding.ascii)) {writer. WriteStartDocument (); Writer. WriteStartElement ("Methodcall"); Writer. WriteElementString ("MethodName", "weblogupdates.ping"); Writer. WriteStartElement ("params"); Writer. WriteStartElement ("param"); Writer. WriteElementString ("value", pingingsitename); Writer. WriteEndElement (); Writer. WriteStartElement ("param"); Writer. WriteElementString ("value", Pingingsiteurl); Writer. WriteEndElement (); Writer. WriteEndElement (); Writer. WriteEndElement (); } request. GetResponse (); } catch (InvalidOperationException ex) {log. Error (ex); } catch (NotSupportedException ex) {log. Error (ex); } } }
NET implementation of Ping methods