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 = (object)(T)requestContent; XmlSerializer serializer = new XmlSerializer(typeof(Envelope)); StringBuilder sb = new StringBuilder(); using (TextWriter textWriter = (TextWriter)new StringWriter(sb)) serializer.Serialize(textWriter, (object)envelope); U content; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "QUZBNUNDMTQzMUNENDNEQ0E2NjNDMTdCREFEODUwQkItQzhGNUJERjlBMDlDNDQ2NEE2NjczMUNBNDQyN0NCQjk6N0FCMzU3NjYtMDM3OS00REYwLTk2NjUtREFFRTEzODIyRjQz"); try { //HttpResponseMessage response = await client.PostAsync(ConfigurationManager.AppSettings["NexpartUrl"], (HttpContent)new StringContent(sb.ToString(), Encoding.UTF8, "text/xml")); HttpResponseMessage response = await client.PostAsync("http://acespssint.nexpart.com:4001/partselect/1.0/services/PartSelectService.PartSelectHttpSoap11Endpoint/", (HttpContent)new StringContent(sb.ToString(), Encoding.UTF8, "text/xml")); Stream result = await response.Content.ReadAsStreamAsync(); string str = await response.Content.ReadAsStringAsync(); content = (U)((Envelope)serializer.Deserialize(result)).Body.Content; } catch (Exception ex) { throw; } } return content; } } }