Estou tentando comunicar com um WebService SOAP. Consegui realizar a comunicação utilizando o SOAPUI conforme imagem:
Estou desenvolvendo essa comunicação em c# da seguinte forma:
try
{
var service = new com.nexxera.flnws001qae.NexxeraWSv2ImplService();
service.RequestSoapContext.Security.Tokens
.Add(new UsernameToken(Properties.Settings.Default.USUARIOWS, Properties.Settings.Default.SENHAWS, PasswordOption.SendPlainText));
var FileName = System.IO.Path.GetFileName(currentFilePath);
service.RequestSoapContext.Attachments.Add(new
Microsoft.Web.Services2.Attachments.Attachment(FileName,
"application/octet-stream", currentFilePath));
service.RequestSoapContext.Add("text/plain", new ContentType());
var c = new StreamReader(currentFilePath).ReadToEnd();
var fs = new com.nexxera.flnws001qae.fileWrapper
{
filename = currentFilePath.Split('\\').Last(),
content = currentFilePath.Split('\\').Last()
};
var arqq = new com.nexxera.flnws001qae.uploadFilev2
{
destination = "LARIND.BANCOS",
file = fs
};
var result = service.uploadFile(arqq);
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
Estou com o seguinte erro:
{"Unsupported content type: application/dime"}
Não consigo setar a opção ContentType:
service.RequestSoapContext.ContentType = "text/plain";
Tentei utilizar o método passado pelo Carlos, chamada do método:
var envelope = new XmlDocument();
envelope.Load("C:\\Nexxera\\teste.xml");
GetResultservice(envelope, "http://flnws001qae.nexxera.com:80/nexxeraws/v2/SkylineWSv2");
conteudo do texte.xml:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:NexxeraWS">
<soapenv:Header/>
<soapenv:Body>
<urn:uploadFile>
<!--Optional:-->
<file>
<filename>C:\Nexxera\log_0615.txt</filename>
<content>C:\Nexxera\log_0614.txt</content>
</file>
<!--Optional:-->
<destination>LARIND.BANCOS</destination>
</urn:uploadFile>
Me retorna erro:
O servidor remoto retornou um erro: (500) Erro Interno do Servidor.
Seguindo o exemplo do Carlos, implemente dessa forma:
public string ProcessAttachment(string fileInput)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://flnws001qae.nexxera.com:80/nexxeraws/v2/SkylineWSv2");
req.Method = "POST";
req.ProtocolVersion = HttpVersion.Version11;
req.Headers.Add("Accept-Encoding", "gzip,deflate");
req.ContentType = "multipart/related; type=\"text/xml\"; start=\"teste\"; boundary=\"----=_Part_72_348989292.1565031692584\"";
req.Headers.Add("SOAPAction", "\"\"");
req.Headers.Add("MIME-Version", "1.0");
//req.ContentLength = 1854;
req.Host = "flnws001qae.nexxera.com:80";
req.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)";
req.KeepAlive = true;
System.Net.ServicePointManager.Expect100Continue = false;
Stream memStream = new System.IO.MemoryStream();
FileStream fileStream = new FileStream(fileInput, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
memStream.Write(buffer, 0, bytesRead);
}
fileStream.Close();
Stream stm = req.GetRequestStream();
memStream.Position = 0;
byte[] tempBuffer = new byte[memStream.Length];
memStream.Read(tempBuffer, 0, tempBuffer.Length);
memStream.Close();
stm.Write(tempBuffer, 0, tempBuffer.Length);
stm.Close();
HttpWebResponse resp = null;
resp = (HttpWebResponse)req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
return r.ReadToEnd();
}
Adicionei o arquivo arq.xml
------=_Part_72_348989292.1565031692584
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: teste
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:NexxeraWS">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-C3491A557C4FE15638156503169258275">
<wsse:Username>homologacao</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">test</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">vbCcpxa/p0Ceton7RevESw==</wsse:Nonce>
<wsu:Created>2019-08-05T19:01:32.582Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<urn:uploadFile>
<!--Optional:-->
<file>
<filename>log_0805.txt</filename>
<content>log_0614.txt</content>
</file>
<!--Optional:-->
<destination>LARIND.BANCOS</destination>
</urn:uploadFile>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_72_348989292.1565031692584
Content-Type: text/plain; charset=us-ascii; name=log_0614.txt
Content-Transfer-Encoding: 7bit
Content-ID: <log_0614.txt>
Content-Disposition: attachment; name="log_0614.txt"; filename="log_0614.txt"
"LA09"; "33007110138"; "110273"; "S0007"; "785522"; "EFETUADA "; "CMPCTCRC"; "00"; "11/04/2019"; "13:06:50"; " 5155******33"; 89; 01; "5155";
------=_Part_72_348989292.1565031692583--
Qual seria a melhor de forma de atualizar esse arquivo.xml, pois para cada arquivo eu vou ter informações diferentes, como o nome, tamanho e diferente informações. Também tem o "----=Part" que deve mudar conforme as informações do meu log...txt.