. NET implementation of Ping instance code _ Practical Tips

Source: Internet
Author: User

Copy Code code as follows:

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);
}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.