Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup http proxy (with user and password) to invoke WCF service reference #4822

Open
nnunes10 opened this issue May 12, 2022 · 3 comments
Open
Assignees
Labels
customer assistance Help customers with questions regarding usage of WCF features.
Projects

Comments

@nnunes10
Copy link

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<HttpsTransportBindingElement>(); // 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.

@HongGit HongGit added this to New Issues in WCF Triage May 13, 2022
@HongGit HongGit moved this from New Issues to In Triage in WCF Triage May 19, 2022
@HongGit HongGit added the customer assistance Help customers with questions regarding usage of WCF features. label May 19, 2022
@HongGit
Copy link
Contributor

HongGit commented Jun 21, 2023

@imcarolwang can you please try to repro this issue?

@imcarolwang
Copy link
Contributor

Hi @nnunes10, I am not sure if this is still a problem to you. Can you try suggestion mentioned at #3311 (comment)? As pointed out in the comment, after configured htbe.ProxyAuthenticationScheme, the proxy would then use whatever credentials you have set for that authentication scheme in your ChannelFactory.ClientCredentials instance. You don't seem to need to create a WebProxy instance for htbe.Proxy in the given code snippet.

@nnunes10
Copy link
Author

Hi @imcarolwang , i will try the solution mentioned on that comment. However, i think i tried it last year without success. In next days i will give an update on this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer assistance Help customers with questions regarding usage of WCF features.
Projects
WCF Triage
In Triage
Development

No branches or pull requests

4 participants