Em meu projeto, preciso me comunicar com um WebService e enviar dados para ele. Porém quando faço o envelopamento e enviou, apresenta o seguinte erro:
"Could not create SSL/TLS secure channel.".
Segue código:
Chamada do Metodo:
string xml = @"<tjce:solicitacaoSelo xmlns:ds=""http://www.w3.org/2000/09/xmldsig#"" xmlns:tjce=""http://www.tjce.jus.br/selodigital/schemas"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.tjce.jus.br/selodigital/schemas xsSolicitacaoSelo_v1.0.xsd "">" +
@"<cabecalho> <versao>1.11</versao> <dataHora>20160913T03:54:09</dataHora> <ambiente>2</ambiente> <serventia> <codigoServentia>000307</codigoServentia> </serventia> </cabecalho> <solicitante> <nomePessoa>CICERO MOZART MACHADO</nomePessoa> <documento> <tipoDocumento>1</tipoDocumento> <numero>90002167595</numero> <descricao>IDENTIDADE</descricao> <orgaoEmissor>SSP-CE</orgaoEmissor> <dataEmissao>1998-03-27</dataEmissao> </documento> <telefone> <tipoTelefone>1</tipoTelefone> <ddd>85</ddd> <numero>32269240</numero> </telefone> <email> <tipoEmail>1</tipoEmail>" +
@"<enderecoEmail>[email protected]</enderecoEmail> </email> </solicitante> <idSolicitacaoSelo>20</idSolicitacaoSelo> <itens> <itemSolicitacao> <sequencial>1</sequencial> <codigoSelo> <codigo>1</codigo> </codigoSelo> <quantidade>1</quantidade> </itemSolicitacao> </itens></tjce:solicitacaoSelo>";
CSoap.ExecutaWebService("https://selodigital.tjce.jus.br/wsselodigital-homologacao/SolicitacaoSelo?wsdl", xml);
Solicitacao.solicitaSelos ws = new Solicitacao.solicitaSelos();
public class CSoap
{
public static void ExecutaWebService(string _url, string xml)
{
HttpWebRequest request = CreateWebRequest(_url);
XmlDocument soapEnvelopeXml = CreateSoapEnvelope(xml);
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
private static HttpWebRequest CreateWebRequest(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction:");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
private static XmlDocument CreateSoapEnvelope(string xml)
{
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema"">
<SOAP-ENV:Body>" + xml + @"</SOAP-ENV:Body></SOAP-ENV:Envelope>");
return soapEnvelop;
}
}