none
Creating Secure Service in .Net RRS feed

  • Question

  • I want to create a secure service using C# .net. I have seem many payment gateway and other services uses following approach:

    string xml = @"xml_request=" + HttpUtility.UrlEncode("XML String", Encoding.UTF8);
    Byte[] data = Encoding.UTF8.GetBytes(xml);
    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
    WebRequest myWebRequest = WebRequest.Create("URL String");
    myWebRequest.ContentType = "application/x-www-form-urlencoded";
    myWebRequest.Method = "POST";
    myWebRequest.ContentLength = data.Length;
    Stream dataStream = myWebRequest.GetRequestStream();
    dataStream.Write(data, 0, data.Length);
    dataStream.Close();
    WebResponse myWebResponse = myWebRequest.GetResponse();
    Stream streamResponse = myWebResponse.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    Char[] readBuff = new Char[256];
    int count = streamRead.Read(readBuff, 0, 256);
    streamResponse.Close();
    streamRead.Close();
    myWebResponse.Close();      

    What is the best way to achieve this? Web service, WCF or Web API? If someone provide sample to do this would be great.

    Thanks

    Friday, January 25, 2013 1:01 PM

Answers