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 service of the actual pinging
</summary>
public void Ping ()
{
Try
{
HttpWebRequest request = (HttpWebRequest) webrequest.create (serviceurltoping);
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);
}
}
}