Created
February 12, 2015 22:36
-
-
Save prakash-patel/6319a8d04c3277c18c1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> HttpCall(string template, X509Certificate2 certificate, string url) | |
{ | |
try | |
{ | |
#region httpClient | |
var httpContent = new StringContent(template, Encoding.UTF8, "application/soap+xml"); | |
var handler = new WebRequestHandler(); | |
handler.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested; | |
handler.ClientCertificates.Add(certificate); | |
var client = new HttpClient(handler); | |
HttpResponseMessage response = await client.PostAsync(url, httpContent); | |
response.EnsureSuccessStatusCode(); | |
Console.WriteLine("status code: ", response.StatusCode.ToString()); | |
var data = await response.Content.ReadAsStreamAsync(); | |
ServicePointManager.ServerCertificateValidationCallback += (sender, certificates, chain, errors) => | |
{ | |
Console.WriteLine("Sender: {0}, Certificate: {1}, Chain: {2}, Errors: {3}", sender, certificates, chain, errors); | |
return true; | |
}; | |
XDocument xDoc = XDocument.Load(data); | |
XNamespace soap = XNamespace.Get("http://www.w3.org/2003/05/soap-envelope"); | |
XNamespace urn = XNamespace.Get("urn:hl7-org:v3"); | |
string valueElement = xDoc.Element(soap + "Envelope") | |
.Element(soap + "Body"); | |
return valueElement; | |
#endregion | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Http Client Erros Message: {0}", ex.Message); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment