52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
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<U> SendRequest<T, U>(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();
|
|
|
|
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:8081/partselect/1.0/services/PartSelectService.PartSelectHttpSoap11Endpoint/", new StringContent(textWriter.ToString(), Encoding.UTF8));
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|