using PartSource.Data.Nexpart; using System; using System.Configuration; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; namespace PartSource.Services { public class NexpartService { public async Task SendRequest(T requestContent) { Envelope envelope = new Envelope(); envelope.Body.Content = requestContent; XmlSerializer serializer = new XmlSerializer(typeof(Envelope)); StringBuilder sb = new StringBuilder(); using (TextWriter textWriter = new StringWriter(sb)) { serializer.Serialize(textWriter, (object)envelope); U content; string x = textWriter.ToString(); System.Diagnostics.Debug.WriteLine(x); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "QjM4ODAyMzM3QjQxNEM2QTk4M0RFMjM0Mjk4Rjk4M0UtOUIzNUUxNzNBQUYxNEE2QjhCQjI2RjZDOUY2ODk1NDU6MkMzOUVCOTYtRDBBRS00QkVBLTlCMzItMUYyNTA5MDJGQTE0"); try { //HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["NexpartUrl"], (HttpContent)new StringContent(sb.ToString(), Encoding.UTF8, "text/xml")); HttpResponseMessage response = await client.PostAsync("http://acespssprod.nexpart.com:8085/partselect/2.0/services/PartSelectService.PartSelectHttpSoap11Endpoint", new StringContent(textWriter.ToString(), Encoding.UTF8, "text/xml")); Stream result = await response.Content.ReadAsStreamAsync(); string str = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine(str); content = (U)((Envelope)serializer.Deserialize(result)).Body.Content; ; } catch (Exception ex) { throw; } } return content; } } } }