Call. Svc Through Soap

Call. Svc Through Soap

I want to write test for .svc through Soap. can any one help me to create HTTPWebRequest for call .svc action.

below is my Sample code

 var url = "";
  var action = "";

 internal static HttpWebRequest CreateWebRequest(string url, string action)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Headers.Add("SOAPAction", action);
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";
            return webRequest;
        }
4

1 Answer

internal  HttpWebRequest CreateWebRequest(string url, string action)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Headers.Add("SOAPAction", action);
            var username = "xxxxx";
            var password = "xxxxx";


            byte[] credentialBuffer = new UTF8Encoding().GetBytes(
                    username + ":" +
                    password);
            webRequest.Headers["Authorization"] =
                    "Basic " + Convert.ToBase64String(credentialBuffer);

            webRequest.PreAuthenticate = true;
            webRequest.ContentType = "text/xml;charset=\"utf-8\"";

            webRequest.Method = "POST";
            return webRequest;
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.