Setup http proxy (with user and password) to invoke WCF service reference
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
I added a wcf service reference to external soap web service. It's all good until i publish the solution to an internal machine which need to setup a http proxy (with Basic auth user/password) to be able to invoke WS.
In .net framework, it was just add a section config to setup the proxy. I need the same in a .net 6 project..
I already tried to create a CustomBinding object to wrap BasicHttpBinding, in order to set the proxy but without success...
Anybody can give me some tips to achieve that? I already tried different approaches, and it does not work...
My code to setup a http proxy in WCF client (without success).
```
EndpointAddress endpoint =
new System.ServiceModel.EndpointAddress("https://.../service");
var binding = new BasicHttpBinding();
binding.MaxBufferSize = int.MaxValue;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.AllowCookies = true;
binding.Security.Mode = BasicHttpSecurityMode.Transport;
// Create customBinding to send the request through proxy which requires user and password (basic auth)
var customBinding = new CustomBinding(binding);
var htbe = customBinding.Elements.Find(); // HTTPS
htbe.ProxyAuthenticationScheme = System.Net.AuthenticationSchemes.Basic;
htbe.UseDefaultWebProxy = false;
//htbe.ProxyAddress = new Uri(string.Format("http://{0}:{1}", settings.Address, settings.Port));
htbe.BypassProxyOnLocal = true;
WebProxy proxy = new WebProxy(new Uri(string.Format("http://{0}:{1}", settings.Address, settings.Port)), true, null);
proxy.Credentials = new NetworkCredential(settings.Username, settings.Password);
htbe.Proxy = proxy;
smsClient = new SubmissionManagerClient(customBinding, endpoint);
//smsClient.ClientCredentials.UserName.UserName = settings.Username;
//smsClient.ClientCredentials.UserName.Password = settings.Password;
```
It seems the proxy is ignored.. I receive the following exception:
```
System.ServiceModel.CommunicationException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (smsexpress.cloud.altice-empresas.pt:443)
---> System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
```
Thanks a lot.
Contributor guide
Assessment
This issue has not been assessed yet.