Inquiridor
Importação Certificado Digital pedindo senha

Pergunta
-
Bom dia
Estou criando uma consulta via web service e nessa consulta estou passando um certificado digital, tenho ele instalado e estou passando local e senha, porém quando faço a consulta ele me dá um erro:
System.InvalidOperationException: O nome de usuário não foi fornecido. Especifique o nome de usuário em ClientCredentials.
Porém eu nao tenho usuário, so tenho senha do certificado, alguém já passou por isso? Ou se realmente o certificado digital contém um usuário e senha?
Obrigado
Todas as Respostas
-
Seu web service pode estar protegido com senha.
Como foi que você o desenvolveu?
Você pode utilizar o artigo abaixo para auxilar você a desabilitar a autenticação.
http://cbsa.com.br/post/protegendo-web-service-com-senha.aspx
Como você está passando o certificado?
-
Eu estou tentando consumir um web service, que seria o do SeFaz.
O meu codigo de configuração está assim:
private List<CadConsultaWebRS.CadConsultaCadastro2Soap12> fields = new List<CadConsultaWebRS.CadConsultaCadastro2Soap12>(); private BasicHttpBinding basicHttpBinding = new BasicHttpBinding() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue }; private EndpointAddress endpointAddress = new EndpointAddress("https://sef.sefaz.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro2.asmx"); private WSHttpBinding wsHttpBinding = new WSHttpBinding(); private CadConsultaWebRS.CadConsultaCadastro2Soap12Client wsTransacional; private CadConsultaWebRS.nfeCabecMsg cab = new CadConsultaWebRS.nfeCabecMsg(); private BindingElement security; public void configuraWebConfig(string _caminhoCertificadoDigital, string _senhaCertificadoDigital) { /********************* Certificado **********************************/ X509Certificate2 certificado = new X509Certificate2(_caminhoCertificadoDigital, _senhaCertificadoDigital, X509KeyStorageFlags.PersistKeySet); /********************* Certificado **********************************/ /********************* SecurityBindingElement **********************************/ var seq = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); seq.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; seq.SecurityHeaderLayout = SecurityHeaderLayout.Lax; seq.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default; security = seq; /********************* SecurityBindingElement **********************************/ /********************* HttpsTransportBindingElement **********************************/ HttpsTransportBindingElement httpstransport = new HttpsTransportBindingElement(); httpstransport.AllowCookies = false; httpstransport.BypassProxyOnLocal = false; httpstransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; httpstransport.MaxBufferSize = 65536; httpstransport.MaxBufferPoolSize = 524288; httpstransport.MaxReceivedMessageSize = 65536; httpstransport.TransferMode = TransferMode.Buffered; //httpstransport.UseDefaultWebProxy = true; httpstransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Digest; httpstransport.ManualAddressing = false; httpstransport.KeepAliveEnabled = true; //httpstransport.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Digest; //httpstransport.UnsafeConnectionNtlmAuthentication = true; httpstransport.RequireClientCertificate = true; /********************* HttpsTransportBindingElement **********************************/ /********************* TextMessageEncodingBindingElement **********************************/ TextMessageEncodingBindingElement oTextMessageEncod = new TextMessageEncodingBindingElement(); oTextMessageEncod.MaxReadPoolSize = 64; oTextMessageEncod.MaxWritePoolSize = 16; oTextMessageEncod.MessageVersion = MessageVersion.Soap12; oTextMessageEncod.WriteEncoding = Encoding.UTF8; /********************* TextMessageEncodingBindingElement **********************************/ /********************* CustomBinding **********************************/ CustomBinding customBinding = new CustomBinding(); customBinding.Name = "CadConsultaCadastro2Soap12"; customBinding.Elements.Add(security); customBinding.Elements.Add(oTextMessageEncod); customBinding.Elements.Add(httpstransport); /********************* CustomBinding **********************************/ /********************* wsTransacional **********************************/ wsTransacional = new CadConsultaWebRS.CadConsultaCadastro2Soap12Client(); wsTransacional.Endpoint.Name = "CadConsultaCadastro2Soap12"; wsTransacional.Endpoint.Contract.Name = "CadConsultaWebRS.CadConsultaCadastro2Soap12"; wsTransacional.Endpoint.Address = endpointAddress; wsTransacional.Endpoint.Binding = customBinding; wsTransacional.ClientCredentials.ClientCertificate.Certificate = certificado; //wsTransacional.ClientCredentials.UserName.UserName = "usuario_certificado"; //wsTransacional.ClientCredentials.UserName.Password = "senha"; /********************* wsTransacional **********************************/ }
Como preciso fazer uma DLL estou transcrevendo tudo do meu web.config para a minha classe.
Obrigado
- Editado Josivan Laskoski terça-feira, 5 de novembro de 2013 13:03 senha
-
-