locked
Not able to set custom proxy to SOAP client with dotnet core 3.1 in linux RRS feed

  • Question

  • User-1294421921 posted

    Dear Experts,

    I have created WebService with SoapCore dll.

    I am trying to call a soap service in my .net core application. It works as expected.

    but when i try to set the proxy i alwas get 407 response http code.

    Please help me to how to set proxy with credentials for SOAP client.

    My environment:

    Ubuntu 20.04 /dotnet core 3.1

    Thanks,

    Kishore

    Wednesday, March 31, 2021 11:05 AM

All replies

  • User-474980206 posted

    on linux you configure the httpclient proxy via environment variables:

    HTTP_PROXY=http://user:password@proxy:port/ 

    see:

    https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultproxy?view=net-5.0

    note: if the proxy uses ntlm (windows auth) its not supported on linux

    Friday, April 2, 2021 3:35 PM
  • User-1294421921 posted

    Thank you very much for the reply.

    My requirement as below:

    I created an application using dotnet core 3.1 in linux environment.

    In this application I generated the SOAP reference using dotnet svcutil tool.

    using the soapcore i am calling the soap service.

    When I make a SOAP request without proxy it works as expected.

    When I make a SOAP request with proxy (set in ubuntu machine) it does not going through proxy.

    I want to set proxy details like proxy ip, port number, username, password.

    I am not able to set, please help me with code snippet.

    Thank you very much.

    Kishore

    Thursday, April 8, 2021 3:43 PM
  • User-474980206 posted

    what part of setting the environment variables did you not understand? the username, password and proxy ipaddress are all there. standard linux url format.

    if using bash or z-shell:

       export HTTP_PROXY="http://username:password@proxy:port"
       export HTTPS_PROXY="https://username:password@proxy:port"
       dotnet myapp.dll

    Thursday, April 8, 2021 7:52 PM
  • User-1294421921 posted

    Thank you very much Mr.bruce,

    The above approach I tried but no luck.

    I can explain with code. I am tring with below code snippet.

    From my dotnet core application making SOAP request to the SOAP service in linux. 

    app1 : dotnet core app (which makes the SOAP request) - PC 1 (ubuntu 20.04 envt)

    app2: asp.net app SOAP service running - PC 2 (windows envt)

    app3: proxy server - PC3 (windows envt)

    If I enable proxy, the SOAP calls are not going thru proxy.

    Please help me.

    It works with below authentication schema.

    httpElement.ProxyAuthenticationScheme = AuthenticationSchemes.Basic;

    but not working with other than authentication schema basic.

    var binding = new BasicHttpBinding();
    
    binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    
    //Wrap binding custombinding to route request through proxy with credential authentication
    var customBinding = new CustomBinding(binding);
    var httpElement = customBinding.Elements.Find<HttpTransportBindingElement>();
    httpElement.ProxyAddress = new Uri("http://<proxyIP>:<proxyPort>");
    httpElement.ProxyAuthenticationScheme = AuthenticationSchemes.Basic;
    httpElement.UseDefaultWebProxy = false;
    
    using (var webClient = new TransparencyPlatformClient(customBinding, FinalEndpoint)
    {
    	webClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication =
            new X509ServiceCertificateAuthentication()
            {
                CertificateValidationMode = X509CertificateValidationMode.None,
                RevocationMode = System.Security.Cryptography.X509Certificates.X509RevocationMode.NoCheck
            };
    
    	webClient.ClientCredentials.UserName.UserName = ProxyUserName;
    	webClient.ClientCredentials.UserName.Password = ProxyPassword;
    
    	webClient.sendMessage(YourMessage);
    }
    Tuesday, May 4, 2021 7:27 AM