コード例 #1
0
        public string Send()
        {
            String result = "";

            myWebRequestMPK.ContentType = "text/xml;charset=\"utf-8\"";
            myWebRequestMPK.Method      = "POST";
            XmlTextWriter w;

            try
            {
                Stream reqStream = myWebRequestMPK.GetRequestStream();
                w            = new XmlTextWriter("routeaccept.xml", Encoding.UTF8);
                w.Formatting = Formatting.None;
                w.WriteStartDocument();
                w.WriteStartElement("route_accept");
                w.WriteStartElement("id");
                w.WriteString(this.RouteID);
                w.WriteEndElement();
                w.WriteStartElement("version");
                w.WriteString(this.Version);
                w.WriteEndElement();
                w.WriteStartElement("accept");
                w.WriteString(this.Accept);
                w.WriteEndElement();
                w.WriteStartElement("vehicle");
                w.WriteString(this.VehicleID);
                w.WriteEndElement();
                if (this.VehicleID != null)
                {
                    w.WriteStartElement("vehicle_capacity");
                    w.WriteStartElement("passengers");
                    w.WriteString(this.VehPax);
                    w.WriteEndElement();
                    w.WriteStartElement("wheelchairs");
                    w.WriteString(this.VehWheels);
                    w.WriteEndElement();
                    w.WriteEndElement();
                }
                w.WriteStartElement("price_group");
                w.WriteString("1");
                //w.WriteString(this.PriceGroup);
                w.WriteEndElement();
                w.WriteStartElement("company_id");
                w.WriteString(this.CompanyID);
                w.WriteEndElement();
                w.WriteEndElement();
                w.Close();

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load("routeaccept.xml");

                log.Info(String.Format("<route_accept> sent: {0}", xDoc.OuterXml));
                //Console.WriteLine("Sending <route_accept> msg: {0}",xDoc.OuterXml);

                MD5Verifier ver = new MD5Verifier(Encoding.UTF8);
                ver.doVerify(xDoc.OuterXml);

                StreamWriter sw = new StreamWriter(reqStream);
                sw.Write(xDoc.OuterXml);
                sw.Write(ver.GetCheckSum());
                sw.Close();
            }
            catch (WebException e)
            {
                log.ErrorFormat("Timeout error awaiting route_accept response from server {0}", e.Message);
                return(null);
            }
            catch (Exception e)
            {
                log.Error(String.Format("Error formatting <route_accept> {0}", e.Message));
                //Console.WriteLine("Exception raised: {0}", e.Message);
            }

            try
            {
                myWebResponseMPK = (HttpWebResponse)myWebRequestMPK.GetResponse();
                using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    log.Info(String.Format("MPK Server reply: {0}", result));
                    //Console.WriteLine("Received reply: {0}", result);
                    return(result);
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    log.Error("Timeout error awaiting route_accept response from server");
                    return(null);
                }
                log.Error(String.Format("MPK Server returned error: {0}", e.Message));
                myWebResponseMPK = (HttpWebResponse)e.Response;
                if (myWebResponseMPK != null)
                {
                    using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                    {
                        result = sr.ReadToEnd();
                        log.InfoFormat("{0}", result);
                    }
                }
                //Console.WriteLine("Server error {0}", e.Message);
                return(null);
            }
        }
コード例 #2
0
        public string Send()
        {
            String result = "";

            myWebRequestMPK.ContentType = "text/xml;charset=\"utf-8\"";
            myWebRequestMPK.Method      = "POST";
            XmlTextWriter w;

            try
            {
                Stream reqStream = myWebRequestMPK.GetRequestStream();
                w            = new XmlTextWriter(@"C:\inetpub\wwwroot\MPKService\Data\locationupdate.xml", Encoding.UTF8);
                w.Formatting = Formatting.None;
                w.WriteStartDocument();
                w.WriteStartElement("location_update");


                w.WriteStartElement("vehicle");
                w.WriteString(this.VehicleID);
                w.WriteEndElement();


                w.WriteStartElement("time");
                w.WriteString(System.DateTime.Now.ToString("yyyyMMdd:HHmmss"));
                w.WriteEndElement();

                w.WriteStartElement("route_id");
                w.WriteString(this.RouteID);
                w.WriteEndElement();

                w.WriteStartElement("location");
                w.WriteAttributeString("x", this.x.ToString());
                w.WriteAttributeString("y", this.y.ToString());
                w.WriteEndElement();
                w.WriteEndElement();
                w.Close();

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(@"C:\inetpub\wwwroot\MPKService\Data\locationupdate.xml");

                //Console.WriteLine("Sending <stop_visit> msg: {0}",xDoc.OuterXml);

                MD5Verifier ver = new MD5Verifier(Encoding.UTF8);
                ver.doVerify(xDoc.OuterXml);

                StreamWriter sw = new StreamWriter(reqStream);
                sw.Write(xDoc.OuterXml);
                sw.Write(ver.GetCheckSum());
                sw.Close();
            }
            catch (Exception e)
            {
                //Console.WriteLine("Exception raised: {0}", e.Message);
            }

            try
            {
                myWebResponseMPK = (HttpWebResponse)myWebRequestMPK.GetResponse();
                using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    Console.WriteLine("Received reply: {0}", result);
                    return(result);
                }
            }
            catch (WebException e)
            {
                myWebResponseMPK = (HttpWebResponse)e.Response;
                using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    log.InfoFormat("{0}", result);
                }
                Console.WriteLine("Server error {0}", e.Message);
                return(e.Message);
            }
        }
コード例 #3
0
ファイル: StopVisit.cs プロジェクト: mbsoft/TaxiPak_NET
        public string Send()
        {
            String result = "";

            myWebRequestMPK.ContentType = "text/xml;charset=\"utf-8\"";
            myWebRequestMPK.Method      = "POST";
            XmlTextWriter w;

            try
            {
                Stream reqStream = myWebRequestMPK.GetRequestStream();
                w            = new XmlTextWriter(@".\stopvisit.xml", Encoding.UTF8);
                w.Formatting = Formatting.None;
                w.WriteStartDocument();
                w.WriteStartElement("stop_visit");
                w.WriteStartElement("id");
                w.WriteString(this.StopID);
                w.WriteEndElement();

                w.WriteStartElement("vehicle");
                w.WriteString(this.VehicleID);
                w.WriteEndElement();


                w.WriteStartElement("arrival_time");
                w.WriteString(this.ArrivalTime);
                //w.WriteString(this.PriceGroup);
                w.WriteEndElement();
                w.WriteStartElement("departure_time");
                w.WriteString(this.DepartureTime);
                w.WriteEndElement();
                w.WriteStartElement("status");
                w.WriteString(this.Status);
                w.WriteEndElement();
                w.WriteStartElement("location");
                w.WriteAttributeString("x", this.x.ToString());
                w.WriteAttributeString("y", this.y.ToString());
                w.WriteEndElement();
                w.WriteEndElement();
                w.Close();

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(@".\stopvisit.xml");

                log.InfoFormat("<stop_visit> sent: {0}", xDoc.OuterXml);
                //Console.WriteLine("Sending <stop_visit> msg: {0}",xDoc.OuterXml);

                MD5Verifier ver = new MD5Verifier(Encoding.UTF8);
                ver.doVerify(xDoc.OuterXml);

                StreamWriter sw = new StreamWriter(reqStream);
                sw.Write(xDoc.OuterXml);
                sw.Write(ver.GetCheckSum());
                sw.Close();
            }
            catch (Exception e)
            {
                log.ErrorFormat("Exception raised in <stop_visit> {0}", e.Message);
                //Console.WriteLine("Exception raised: {0}", e.Message);
            }

            try
            {
                myWebResponseMPK = (HttpWebResponse)myWebRequestMPK.GetResponse();
                using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    log.InfoFormat("Received server reply: {0}", result);
                    //Console.WriteLine("Received reply: {0}", result);
                    return(result);
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    log.Error("Timeout error awaiting StopVisit response from server");
                    return(null);
                }

                log.ErrorFormat("Error with server reply: {0}", e.Message);
                myWebResponseMPK = (HttpWebResponse)e.Response;
                if (myWebResponseMPK != null)
                {
                    using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                    {
                        result = sr.ReadToEnd();
                        log.InfoFormat("{0}", result);
                    }
                }
                //Console.WriteLine("Server error {0}", e.Message);
                return(e.Message);
            }
        }
コード例 #4
0
ファイル: Ping.cs プロジェクト: mbsoft/TaxiPak_NET
        public string Send()
        {
            String result = "";

            myWebRequestMPK.ContentType = "text/xml;charset=\"utf-8\"";
            myWebRequestMPK.Method      = "POST";
            XmlTextWriter w;

            try
            {
                Stream reqStream = myWebRequestMPK.GetRequestStream();
                w            = new XmlTextWriter(@".\ping.xml", Encoding.UTF8);
                w.Formatting = Formatting.None;
                w.WriteStartDocument();
                w.WriteStartElement("ping");
                w.WriteEndElement();
                w.Close();

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(@".\ping.xml");

                log.InfoFormat("<ping> sent: {0}", xDoc.OuterXml);
                Console.WriteLine("Sending <ping> msg: {0}", xDoc.OuterXml);

                MD5Verifier ver = new MD5Verifier(Encoding.UTF8);
                ver.doVerify(xDoc.OuterXml);

                StreamWriter sw = new StreamWriter(reqStream);
                sw.Write(xDoc.OuterXml);
                sw.Write(ver.GetCheckSum());
                sw.Close();
            }
            catch (Exception e)
            {
                log.ErrorFormat("Exception raised in <ping> {0}", e.Message);
                Console.WriteLine("Exception raised: {0}", e.Message);
            }

            try
            {
                myWebResponseMPK = (HttpWebResponse)myWebRequestMPK.GetResponse();
                using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    log.InfoFormat("Received server reply: {0}", result);
                    Console.WriteLine("Received reply: {0}", result);
                    return(result);
                }
            }
            catch (WebException e)
            {
                log.ErrorFormat("Error with server reply: {0}", e.Message);
                myWebResponseMPK = (HttpWebResponse)e.Response;
                using (StreamReader sr = new StreamReader(myWebResponseMPK.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    log.InfoFormat("{0}", result);
                }
                Console.WriteLine("Server error {0}", e.Message);
                return(e.Message);
            }
        }