Я пытаюсь подключиться к службе WCF через прокси.Прокси имеет аутентификацию по логину-паролю.
Мой код:
var proxyHost = "http://127.0.0.1:3128/";
var proxyUserName = "username";
var proxyUserPassword = "userpassword";
var apiConnectAddress = "https://remoteaddress/service.svc";
var binding = new BasicHttpBinding
{
UseDefaultWebProxy = false,
ProxyAddress = new Uri(proxyHost)
Security =
{
Mode = BasicHttpSecurityMode.Transport,
Transport =
{
ClientCredentialType = HttpClientCredentialType.None,
ProxyCredentialType = HttpProxyCredentialType.Basic
}
}
};
var client = new Client(binding, new EndpointAddress(apiConnectAddress));
client.ClientCredentials.UserName.UserName = proxyUserName;
client.ClientCredentials.UserName.Password = proxyUserPassword;
client.SomeMethod(...); // an exception occurs here
class Client : System.ServiceModel.ClientBase<T> { ... }
Сведения об исключении:
System.ServiceModel.ProtocolException
HResult=0x80131500
Message=The remote server returned an unexpected response: (407) Proxy
Authentication Required.
Source=System.Private.ServiceModel
StackTrace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
Насколько я понимаю, исключение происходит из-за входа в систему ипароль не передается на прокси-сервер.Как настроить HttpBinding для успешного подключения к сервису через прокси?
PS.Приложение написано на .Net Core 2.2