public static ReturnType Create <ReturnType>()
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(
            string.Format("{0}/Create?EntityName='{1}'",
                          sUri.TrimEnd('/'),
                          typeof(ReturnType).Name)
            );
        NetworkCredential serviceCreds = new NetworkCredential(UserName, Password);
        CredentialCache   cache        = new CredentialCache();

        cache.Add(new Uri(sUri), "Basic", serviceCreds);

        req.Credentials = cache;
        req.Method      = "GET";
        req.ContentType = "application/xml";
        req.Timeout     = 1000 * 60 * 15; // 15 minutes

        try
        {
            HttpWebResponse resp     = (HttpWebResponse)req.GetResponse();
            var             response = new StreamReader(resp.GetResponseStream()).ReadToEnd();
            //XDocument doc = XDocument.Load(resp.GetResponseStream());
            XDocument doc = XDocument.Parse(response);

            resp.Close();
            ReturnType oEntity = doc.Root.ToString().ToBusinessEntity <ReturnType>(SourceFormatEnum.XML);
            return(oEntity);
        }
        catch (WebException wex)
        {
            throw DataServiceExceptionUtil.ParseException(wex);
        }
    }
    public static string FileUpload(byte[] fileContent, string TargetFileName)
    {
        HttpWebRequest    req          = (HttpWebRequest)WebRequest.Create(sUri.TrimEnd('/') + "/FileUpload?fileName='" + TargetFileName + "'");
        NetworkCredential serviceCreds = new NetworkCredential(UserName, Password);
        CredentialCache   cache        = new CredentialCache();
        Uri uri = new Uri(sUri);

        cache.Add(uri, "Basic", serviceCreds);
        req.Credentials = cache;
        req.Method      = "POST";
        req.Timeout     = 1000 * 60 * 20; // 20 minutes
        req.SendChunked = true;

        req.ContentLength = fileContent.Length;
        Stream reqStrm = req.GetRequestStream();

        reqStrm.Write(fileContent, 0, fileContent.Length);
        reqStrm.Close();

        try
        {
            HttpWebResponse resp     = (HttpWebResponse)req.GetResponse();
            var             response = new StreamReader(resp.GetResponseStream()).ReadToEnd();
            //XDocument doc = XDocument.Load(resp.GetResponseStream());
            XDocument doc = XDocument.Parse(response);
            resp.Close();
            return(doc.Root.Value);
        }
        catch (WebException wex)
        {
            throw DataServiceExceptionUtil.ParseException(wex);
        }
    }
    private static ReturnType DoPost <ReturnType>(string SvcOperName, object o, bool enableAuthentication)
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sUri.TrimEnd('/') + "/" + SvcOperName);

        if (enableAuthentication)
        {
            NetworkCredential serviceCreds = new NetworkCredential(UserName, Password);
            CredentialCache   cache        = new CredentialCache();
            Uri uri = new Uri(sUri);
            cache.Add(uri, "Basic", serviceCreds);
            req.Credentials = cache;
        }

        req.Method = "POST";
        //req.ContentType = "application/x-www-form-urlencoded";
        req.ContentType = "application/xml";
        req.Timeout     = 1000 * 60 * 15; // 15 minutes

        byte[] arr = o.ToSerializedByteArrayUTF8();
        req.ContentLength = arr.Length;
        Stream reqStrm = req.GetRequestStream();

        reqStrm.Write(arr, 0, arr.Length);
        reqStrm.Close();

        try
        {
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            var stream = resp.GetResponseStream();

            if (stream.CanRead)
            {
                var response = new StreamReader(stream).ReadToEnd();
                //XDocument doc = XDocument.Load(stream);
                XDocument doc = XDocument.Parse(response);
                resp.Close();
                ReturnType oResp = doc.Root.ToString().ToBusinessEntity <ReturnType>(SourceFormatEnum.XML);
                return(oResp);
            }
            else
            {
                return(default(ReturnType));
            }
        }
        catch (WebException wex)
        {
            throw DataServiceExceptionUtil.ParseException(wex);
        }
    }
    public static ReturnType Delete <ReturnType>(object entityToDelete)
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(
            string.Format("{0}/Delete?EntityName='{1}'",
                          sUri.TrimEnd('/'),
                          typeof(ReturnType).Name)
            );
        NetworkCredential serviceCreds = new NetworkCredential(UserName, Password);
        CredentialCache   cache        = new CredentialCache();
        Uri uri = new Uri(sUri);

        cache.Add(uri, "Basic", serviceCreds);

        req.Credentials = cache;
        req.Method      = "POST";
        req.ContentType = "application/xml";
        req.Timeout     = 1000 * 60 * 15; // 15 minutes

        byte[] arr = entityToDelete.ToSerializedByteArrayUTF8();
        req.ContentLength = arr.Length;
        Stream reqStrm = req.GetRequestStream();

        reqStrm.Write(arr, 0, arr.Length);
        reqStrm.Close();

        try
        {
            HttpWebResponse resp     = (HttpWebResponse)req.GetResponse();
            var             response = new StreamReader(resp.GetResponseStream()).ReadToEnd();
            //XDocument doc = XDocument.Load(resp.GetResponseStream());
            XDocument doc = XDocument.Parse(response);
            resp.Close();
            ReturnType oResp = doc.Root.ToString().ToBusinessEntity <ReturnType>(SourceFormatEnum.XML);
            return(oResp);
        }
        catch (WebException wex)
        {
            throw DataServiceExceptionUtil.ParseException(wex);
        }
    }