Exemple #1
0
 /// <summary>
 /// Gets a ping back
 /// </summary>
 /// <param name="Request">The HttpRequest for this item</param>
 /// <returns>The ping back message</returns>
 public static PingBackMessage GetPingBack(HttpRequest Request)
 {
     PingBackMessage TempMessage = new PingBackMessage();
     TempMessage.Source = "";
     TempMessage.Target = "";
     string RequestText = GetRequest(Request);
     if (!RequestText.Contains("<methodName>pingback.ping</methodName>"))
     {
         return TempMessage;
     }
     XmlDocument XMLDocument = new XmlDocument();
     XMLDocument.LoadXml(RequestText);
     XmlNodeList Nodes = XMLDocument.SelectNodes("methodCall/params/param/value/string");
     if (Nodes == null)
     {
         Nodes = XMLDocument.SelectNodes("methodCall/params/param/value");
     }
     if (Nodes != null)
     {
         TempMessage.Source = Nodes[0].InnerText.Trim();
         TempMessage.Target = Nodes[1].InnerText.Trim();
     }
     return TempMessage;
 }
Exemple #2
0
        /// <summary>
        /// Sends a ping back
        /// </summary>
        /// <param name="Message">Message to send</param>
        public static void SendPingBack(PingBackMessage Message)
        {
            if (string.IsNullOrEmpty(Message.Source) || string.IsNullOrEmpty(Message.Target))
                return;

            HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(new Uri(Message.Target));
            Request.Credentials = CredentialCache.DefaultNetworkCredentials;
            HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
            string PingURL = (!string.IsNullOrEmpty(Response.Headers["x-pingback"])) ? Response.Headers["x-pingback"] : Response.Headers["pingback"];
            Uri URIUsing;
            if (!string.IsNullOrEmpty(PingURL) && Uri.TryCreate(PingURL, UriKind.Absolute, out URIUsing))
            {
                Request = (HttpWebRequest)HttpWebRequest.Create(URIUsing);
                Request.Method = "POST";
                Request.Timeout = 10000;
                Request.ContentType = "text/xml";
                Request.ProtocolVersion = HttpVersion.Version11;
                Request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)";
                using (XmlTextWriter Writer = new XmlTextWriter(Request.GetRequestStream(), Encoding.ASCII))
                {
                    Writer.WriteStartDocument(true);
                    Writer.WriteStartElement("methodCall");
                    Writer.WriteElementString("methodName", "pingback.ping");
                    Writer.WriteStartElement("params");
                    Writer.WriteStartElement("param");
                    Writer.WriteStartElement("value");
                    Writer.WriteElementString("string", Message.Source);
                    Writer.WriteEndElement();
                    Writer.WriteEndElement();
                    Writer.WriteStartElement("param");
                    Writer.WriteStartElement("value");
                    Writer.WriteElementString("string", Message.Target);
                    Writer.WriteEndElement();
                    Writer.WriteEndElement();
                    Writer.WriteEndElement();
                    Writer.WriteEndElement();
                }
                Request.GetResponse();
            }
        }