通信するために基本認証を必要とするJavaベースのWebサービスがあります。ブラウザにWSDLURLを入力すると、基本認証の入力を求められます。正しいクレデンシャルを入力することで取得できます。
ただし、WCFクライアントを使用しても機能しません。
私は次のようにWCFクライアントを構築します。
var binding = new BasicHttpBinding
{
MaxReceivedMessageSize = 2048 * 10240,
Security = {
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Transport = {
ClientCredentialType = HttpClientCredentialType.Basic,
Realm = "MYREALM",
ProxyCredentialType = HttpProxyCredentialType.None
},
Message = {
ClientCredentialType = BasicHttpMessageCredentialType.UserName,
AlgorithmSuite = SecurityAlgorithmSuite.Default
}
}
};
var client = new WebServiceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;
client.DoWebServiceMethod();
次の例外が発生します。
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="MYREALM"'.
私が言えることから、私は物事を正しくやっています。どこが間違っているのですか?