2012-10-03 25 views
-1

我知道这个错误非常常见,但我尝试将解决方案应用于此问题,但无法解决这个问题(407)需要代理身份验证(ISA服务器需要授权才能完成请求,拒绝访问Web代理筛选器

那是我的代码:

 var endpoint = new EndpointAddress(new Uri("http://www3prz.bancobonsucesso.com.br/Servicos/app.svc"), EndpointIdentity.CreateDnsIdentity("bancobonsucesso.com.br")); 
     var binding = new WSHttpBinding(); 

     binding.UseDefaultWebProxy = true; 
     binding.Security.Mode = SecurityMode.Message; 
     binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; 
     binding.Security.Message.EstablishSecurityContext = true; 
     binding.Security.Message.NegotiateServiceCredential = true; 

     var customBinding = new CustomBinding(binding); 

     SymmetricSecurityBindingElement security = customBinding.Elements.Find<SymmetricSecurityBindingElement>(); 
     security.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue; 
     security.LocalClientSettings.DetectReplays = false; 

     SecureConversationSecurityTokenParameters secureTokenParams = (SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters; 
     SecurityBindingElement bootstrap = secureTokenParams.BootstrapSecurityBindingElement; 
     bootstrap.LocalClientSettings.MaxClockSkew = TimeSpan.MaxValue; 
     bootstrap.LocalClientSettings.DetectReplays = false; 

     ws = new ServicoClient(customBinding, endpoint); 
     ws.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
     ws.ClientCredentials.UserName.UserName = "test"; 
     ws.ClientCredentials.UserName.Password = "test"; 

     var return = ws.EmitirBoleto("test"); 
+0

你真的需要做的不仅仅是张贴一大堆代码的转储和错误信息。与我们交谈。你说你已经尝试了一堆东西,好吧,你试过了什么?你有什么看法没有帮助?你究竟在做什么,这是行不通的?实际发生的错误是什么?它总是发生,还是有时?如果有时候,你知道什么时候发生? – Servy

+0

错误发生在“ws.EmitirBoleto(”test“)”行上。 无处不在,提示是使用“binding.UseDefaultWebProxy = true”,但错误在使用或不使用此选项时保持不变。 如果我在没有代理的机器上运行,完美工作,但是当我在Internet Explorer中设置代理时,开始发出此错误。 我希望我已经更清楚了。 – Marquinho

+0

您应该将所有这些信息编辑为实际问题,而不是将其作为评论。 – Servy

回答

1

WCF中绑定使用useDefaultWebProxy:

<bindings> 
<basicHttpBinding> 
<binding name="bindingName" useDefaultWebProxy="true"> 

WebProxy wproxy = new WebProxy("new proxy",true); 
wproxy.Credentials = new NetworkCredential("user", "pass"); 
WebRequest.DefaultWebProxy = wproxy; 
+0

行“ws = new ServicoClient(customBinding,endpoint)”引用类System.ServiceModel.ClientBase。我无法找到对象/属性WebRequest.DefaultWebProxy – Marquinho

+1

我不知道的是WebRequest是一个静态类 – Marquinho

+0

:)正是@Marquinho。 –

0

这个错误可能与代理服务器设置出现问题。请使用网页浏览器检查代理服务器设置。只是改变了连接设置选项 - >设置 - >连接设置自动检测代理设置

好运...

相关问题