0

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 がプロキシ例外を取得すると想定しています。

いつものように、どんな助けも大歓迎です!よろしくお願いします。

4

1 に答える 1

0

権限の問題です。Web サービスのreadパーミッションはおそらく に設定されています。Anonymousこれは、誰もが WSDL を表示できることを意味しますが、そのexecuteパーミッションは別のものに設定されています。これを確認するには、execute権限をに設定しAnonymous、再試行してください。

次に、資格情報をどのように渡すかが問題になります。おそらく、IS ユーザーを作成することから始めて、それをグループに追加し、そのグループを Web サービスの実行権限に設定します。次に、そのユーザーのユーザー名とパスワードをコードにハードコードします。

それが機能して満足したら、認証/承認が必要な場合は、実際のシステムにシングル サインオン (SAML など) を設定することをお勧めします。

于 2013-10-30T13:12:02.683 に答える