Ping service-use C # To send the ping command to a Windows desktop program

Source: Internet
Author: User

In my previous articleArticlePing service -- is your blog "pinged? In, I introduced some situations of the ping service technology, and then I mentioned that my current virtual host does not support the ping command sending function, this allows me to write a desktop that sends the ping command.Program.

Currently, client requests for ping service have two interfaces: weblogupdates. Ping and weblogupdates. extendedping, which are compatible with the former. Most Ping service servers support both interfaces at the same time, but the ping commands for these two versions are usually processed in the same way, that is, they are all processed in weblogupdates. Ping mode. Considering the future development, I decided to use only the weblogupdates. extendedping interface in the program.

The xml rpc request of the weblogupdates. extendedping interface is defined as follows:
RPC endpoint:
Is the server address that provides Ping service, such as: http://rpc.weblogs.com/RPC2
Call Method Name:
Weblogupdates. extendedping
Parameters: (send in the following order)
Blog name
String, up to 1024 characters. For example, "tiray software blog"
Blog website address
String, up to 255 characters. For example: "http://www.tiray.net"
Blog website subscription address
String, up to 255 characters. For example, "http://www.tiray.net/syndication.axd"
Page url to be updated
String, up to 255 characters. For example, "http://www.tiray.net/default.aspx"
Blog tag
Optional. It is a string of up to 1024 characters. Multiple tags are separated by "|. For example, "Software Development |. Net | C #"

The xml rpc response of the weblogupdates. extendedping interface includes three parameters:
Flerror
Boolean. If an error exists, the value is 1.
Message
String. If the request is sent successfully, "thanks for the ping." is usually returned. If flerror is 1, an error message is returned.
Legal
String, the declaration of Ping service provider, usually empty. The legal value of weblog.com is: "You agree that use of the weblogs.com Ping Service is governed by the terms of use found at www.weblogs.com ."
For more information about the ping service client, see the consumer service API description.
The following shows how the ping command is sent in my program:
Private void Ping (string URL)
{
Try
{
Thread. Sleep (500 );
Httpwebrequest request = (httpwebrequest) webrequest. Create (URL );
Request. method = "Post ";
Request. contenttype = "text/XML ";
Request. Timeout = 3000;
Request. Credentials = credentialcache. defaultnetworkcredentials;
Addxmltorequest (request );
Using (httpwebresponse response = (httpwebresponse) request. getresponse ())
{
Xmldocument Doc = new xmldocument ();
Doc. Load (response. getresponsestream ());
......
}
}
Catch (exception E)
{
......
}
}
/// <Summary>
/// Construct the ping service RPC-XML request.
/// </Summary>
Private void addxmltorequest (httpwebrequest request)
{
Stream stream = (Stream) request. getrequeststream ();
Using (xmltextwriter writer = new xmltextwriter (stream, encoding. ASCII ))
{
Writer. writestartdocument ();
Writer. writestartelement ("methodcall ");
Writer. writeelementstring ("methodname", "weblogupdates. extendedping ");
Writer. writestartelement ("Params ");
Writer. writestartelement ("Param ");
Writer. writeelementstring ("value", tb_blogname.text.trim ());
Writer. writeendelement ();
Writer. writestartelement ("Param ");
Writer. writeelementstring ("value", tb_blogurl.text.trim ());
Writer. writeendelement ();
Writer. writestartelement ("Param ");
Writer. writeelementstring ("value", tb_pageurl.text.trim ());
Writer. writeendelement ();
Writer. writestartelement ("Param ");
Writer. writeelementstring ("value", tb_feedurl.text.trim ());
Writer. writeendelement ();
Writer. writestartelement ("Param ");
Writer. writeelementstring ("value", tb_tags.text.trim ());
Writer. writeendelement ();
Writer. writeendelement ();
Writer. writeendelement ();
}
}

Now I have a tool that can run the ping command in a Windows desktop environment. Despite the trouble, I have to run this program to send the ping command every time I update my blog, however, the advantage is that it is more intuitive and can be sent as soon as you want. The final program interface is shown as follows. I listed the latest 15 updates of the tiray software blog on the right side. I 'd like to publicize it for myself!


If you are interested in this program, you can download it from the following address. Note that I wrote it in C #. If your computer does not have the annoying code of over 10 MB. net Framework 2.0 ......
:
Http://www.tiray.net/page/Tiray-Blog-Ping.aspx

If you want to learn more about the xml rpc technology, visit http://www.xml-rpc.net/. this is an open source CEN project. You can use a ticket to ping the Service server.

From: http://www.cnblogs.com/tiray/archive/2008/05/14/1196602.html

Related Article

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.