How to set proxy credentials to specific wcf client?

后端 未结 3 1000
渐次进展
渐次进展 2020-12-29 06:14

I need to connect to some public wcf service, but there is some proxy between me and service. If i use default proxy settings such as


  &l         


        
相关标签:
3条回答
  • 2020-12-29 06:27

    I found a solution. You have to update WCF to the latest.

    Go to NuGet Package Manager -> Update all related Project URL of WCF There must be:

    System.ServiceModel.Security
    System.ServiceModel.NetTcp
    System.ServiceModel.Http
    

    This apply to .net core 2.1 version.

    0 讨论(0)
  • 2020-12-29 06:28

    You can try this

    HttpWebRequest request = HttpWebRequest.Create("URI") as HttpWebRequest;
    var proxy = new WebProxy(HttpWebRequest.GetSystemWebProxy().GetProxy(request.RequestUri), true);
    proxy.Credentials = new NetworkCredential(proxyUserName, proxyPassword, DomainName);
    request.Proxy = proxy;
    

    hope it helps

    0 讨论(0)
  • 2020-12-29 06:39

    Here's an article dealing with this issue.

    http://blogs.msdn.com/b/stcheng/archive/2008/12/03/wcf-how-to-supply-dedicated-credentials-for-webproxy-authentication.aspx

    In summary, this is how to set a proxy for a specific service in the web.config. In the binding config, set proxyAddress="http://myproxy:8080" and set useDefaultWebProxy="false"

    <bindings>
      <basicHttpBinding>
         <binding name="SubscriberFulfilmentServiceSOAP12Binding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
          textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false"
    proxyAddress="http://myproxy:8080"
          messageEncoding="Text">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    
    0 讨论(0)
提交回复
热议问题