soaphttpclientprotocol Cachesプロキシ資格情報?
-
10-10-2019 - |
質問
.NET4では、SoaphttpClientProtocolがプロキシ資格情報をキャッシュするように見えることに気付きました。これが真実かどうか、そしてこのキャッシュを更新する方法を誰かが知っていますか?私のユーザーが資格情報を変更した場合、私はそれらを試してみたいが、soaphttpclientProtocolを取得して正常に接続すると、呼び出しへの呼び出しが機能するように見えます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Web.Services;
class Program : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public Program()
{
base.Url = "something";
}
static void Main(string[] args)
{
Program x = new Program();
x.Proxy = new WebProxy("basicproxy", 2121);
x.Proxy.Credentials = new NetworkCredential("proxyuser", "IncorrectPassword");
Console.WriteLine("Attempt with proxyuser and IncorrectPassword: " + x.NoOp());
x.Proxy.Credentials = new NetworkCredential("proxyuser", "password");
Console.WriteLine("Attempt with proxyuser and password: " + x.NoOp());
x.Proxy.Credentials = new NetworkCredential("proxyuser", "IncorrectPassword");
Console.WriteLine("Attempt with proxyuser and IncorrectPassword: " + x.NoOp());
Program y = new Program();
y.Proxy = new WebProxy("basicproxy", 2121);
y.Proxy.Credentials = new NetworkCredential("proxyuser", "IncorrectPassword");
Console.WriteLine("Attempt with proxyuser and IncorrectPassword: " + y.NoOp());
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("...", RequestNamespace = "...", ResponseNamespace = "...", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool NoOp()
{
try
{
object[] results = this.Invoke("NoOp", new object[0]);
return ((bool)(results[0]));
}
catch (WebException e)
{
if (e.Response != null && ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ProxyAuthenticationRequired)
{
Console.WriteLine("incorrect Credential attempt!");
}
else
{
Console.WriteLine("Exception: " + e.Message);
}
}
return false;
}
このプログラムの出力(最後の2つが虚偽であると予想しています)
incorrect Credential attempt!
Attempt with proxyuser and IncorrectPassword: False
Attempt with proxyuser and password: True
Attempt with proxyuser and IncorrectPassword: True
Attempt with proxyuser and IncorrectPassword: True
解決
簡単に見てください HttpWebRequest
リフレクターでは、それが区別されないことを示しています ServicePoint
プロキシ資格情報に基づくオブジェクト。したがって、これらすべてのリクエストに対して同じHTTP接続プールを再利用し、最初の成功したプロキシ認証の後も同じ接続が生き続けるため、最後の2つのリクエストに提供された資格情報を使用しようとさえしません。
設定してみてください ConnectionGroupName
設定した時点でプロキシユーザー名とパスワードを含むいくつかの文字列へのプロパティ Proxy
プロパティ(ヘルパーメソッドがあるかもしれません)。
別のオプションは、proxyuser:password@BasicProxy:2121 URLスキームを使用することです。 WebProxy
コンストラクタ。
所属していません StackOverflow