void LogMessage(string methodName, Message msg)
        {
            Common.CustomTextTraceSource ts = new Common.CustomTextTraceSource("WeatherStationService.CommercialVehicleMessageInspector." + methodName,
               "MyTraceSource", SourceLevels.Information);


            if (msg != null)
            {
                ts.TraceInformation("Message:");
                //request.CreateBufferedCopy(int.MaxValue)
                ts.TraceInformation(msg.ToString());
                //file.WriteLine(msg.CreateBufferedCopy(int.MaxValue).ToString());
            }
            else
            {
                ts.TraceInformation("Message == NULL");
            }
        }
        public virtual uploadPhotoResponse uploadPhoto(uploadPhotoRequest request)
        {
            try
            {
                string uploadPath = AppDomain.CurrentDomain.BaseDirectory;

                Common.CustomTextTraceSource ts = new Common.CustomTextTraceSource("CommercialVehicleCollisionWSPImpl.CommercialVehicleCollisionWebService.getDocument",
                    "MyTraceSource", SourceLevels.Information);

                ts.TraceInformation("Upload Path: <{0}>", uploadPath != null ? uploadPath : "NULL");

                string uploadFolder = ConfigurationManager.AppSettings["UploadFolder"];
                                
                if (String.IsNullOrEmpty(uploadFolder))
                {
                    throw new InvalidOperationException("Upload folder not present.");
                }

                string upLoadFullPath = Path.Combine(uploadPath, uploadFolder);

                if (!Directory.Exists(upLoadFullPath))
                {
                    //Directory.CreateDirectory(upLoadFullPath);
                    throw new InvalidOperationException("Upload folder not present.");
                }


                string _uploadFilename = ConfigurationManager.AppSettings["UploadFilePrefix"];

                string photoId = System.Guid.NewGuid().ToString();
                _uploadFilename += photoId;
                _uploadFilename += ".jpg";


                string path = Path.Combine(upLoadFullPath, _uploadFilename);

                ts.TraceInformation("Path: <{0}>", path != null ? path : "NULL");
                
                if (File.Exists(path))
                {
                    if ((File.GetAttributes(path) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        File.SetAttributes(path, FileAttributes.Normal);
                    }

                    File.Delete(path);
                }

                _uploadFilename = path;

                SaveImage(_uploadFilename, request.Photo);

                uploadPhotoResponse photoResponse = new uploadPhotoResponse(photoId);

                return photoResponse;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Server exception: " + e.ToString());

                throw;
            }
        }
        public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
        {   
            byte[] msgContents = new byte[buffer.Count];
            Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
            bufferManager.ReturnBuffer(buffer.Array);

            MemoryStream stream = new MemoryStream(msgContents);

            Common.CustomTextTraceSource ts = new Common.CustomTextTraceSource("CustomTextMessageEncoder.CustomTextMessageEncoder.ReadMessage",
                            "MyTraceSource", SourceLevels.Information);

            string xmlstring = string.Empty;

            try
            {
                MemoryStream tmpStream = new MemoryStream(msgContents);

                var sr = new StreamReader(tmpStream);
                xmlstring = sr.ReadToEnd();

                ts.TraceInformation(xmlstring);

                //XmlDocument signedDoc = new XmlDocument() { PreserveWhitespace = false };

                //signedDoc.LoadXml(xmlstring);

                //XmlSigner verifier = new XmlSigner(signedDoc);

                //XmlElement sigElement = GetSignatureElement(signedDoc, @"http://www.w3.org/2000/09/xmldsig#", "Security");

                //bool valid = false;
                //if (sigElement != null)
                //{
                //    //valid = verifier.ValidateSignature(sigElement, algorithm);
                //    valid = verifier.ValidateSignature(sigElement);

                //    file.WriteLine("Signature Validation = " + valid.ToString());
                //}
            }
            catch (Exception e)
            {
                ts.TraceInformation("Exception:  " + e.Message);
                if (e.InnerException != null)
                {
                    ts.TraceInformation("InnerException:  " + e.InnerException.Message);
                }

            }

            //file.WriteLine("Request Message: ");
            //file.WriteLine(xmlstring);

            //file.Close();

            return ReadMessage(stream, int.MaxValue);
        }