2 つの Web メソッド サーバーがあり、1 つは内部ネットワーク経由でアクセスでき、もう 1 つはネットワークの外部からアクセスできます。両方の WSDL にアクセスできるので、サービスが正常に稼働していることがわかります。
次の .NET コードは、外部サーバーで実行すると機能します (したがって、外部 Web メソッド サーバーにアクセスしています)。
public WebMethodsService()
{
var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
var ea = new
EndpointAddress(ConfigurationManager.AppSettings["WebMethodsServer"]);
_client = new vendorSelfService_PortTypeClient(binding, ea);
if (_client.ClientCredentials != null)
{
_client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["WebMethodsUserName"];
_client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["WebMethodsPassword"];
}
_timeout = int.MaxValue.ToString(CultureInfo.InvariantCulture);
_port = ConfigurationManager.AppSettings["WebMethodsInvokeUriPort"];
_url = ConfigurationManager.AppSettings["WebMethodsInvokeUri"];
}
public bool ValidateUser(string userName, string password)
{
var find = new ValidateUser
{
userName = userName,
password = password
};
fault17 foundFault;
transportInfo17 transportInfo;
var response = _client.ISearch_ValidateUser(find, null, _timeout, _port, _url, null, out foundFault, out transportInfo);
ProcessWebMethodsResponse(response, foundFault, transportInfo);
return response.ValidateUserResult;
}
public void ProcessWebMethodsResponse(object results, object fault, object info)
{
if (fault != null)
{
var correctFault = new fault();
WebMethodsMapper.MapProperties(fault, correctFault);
var correctTransport = new transportInfo();
WebMethodsMapper.MapProperties(info, correctTransport);
var anyFaults = correctFault.ToFaultString(correctTransport);
if (!string.IsNullOrEmpty(anyFaults))
{
throw new WebException(anyFaults);
}
}
if (results == null)
{
throw new InvalidDataException("Cannot find results...");
}
}
ローカル マシンで Visual Studio の IDE を使用してコードを実行しようとすると、問題が発生します。次のエラーが一貫して表示されます。
私の調査によると、.NET と Web メソッドの使用には問題があることがわかりました。.NET は、Web メソッドが期待する方法で認証をネゴシエートしません。
プロキシに例外を追加すると、Internet Explorer のブラウザ内でのみ WSDL にアクセスできるようになります。このコードのどこでそれを行うのかわかりません... 特に web.config ファイルでプロキシを使用するように指示していない場合、.NET がプロキシ例外を取得すると想定しています。
いつものように、どんな助けも大歓迎です!よろしくお願いします。