2

2 つの同一のサーバーがあります。どちらも Win2k3 です。メールをキューに入れる Web サービスと、そのサービスを利用するアプリケーションがあります。どちらも、同一のフォルダ構造、アクセス許可、および IIS 設定を使用して、両方のマシンでホストされています。1 つは "test" と呼ばれ、もう 1 つは "prod" と呼ばれます。

理想的には、本番環境のアプリは本番環境の ws を指します。ただし、その場合、次のエラーページが表示されます。

「/Apps/UTMv1」アプリケーションでサーバー エラーが発生しました。

リクエストは HTTP ステータス 401: Unauthorized で失敗しました。説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。

例外の詳細: System.Net.WebException: HTTP ステータス 401 で要求が失敗しました: 権限がありません。

ソース エラー:

現在の Web 要求の実行中に未処理の例外が生成されました。例外の発生元と場所に関する情報は、以下の例外スタック トレースを使用して特定できます。

スタックトレース:

[WebException: HTTP ステータス 401: Unauthorized でリクエストが失敗しました。]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage メッセージ、WebResponse 応答、ストリーム responseStream、ブール値の asyncCall) +431201 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName、Object[] パラメーター) +204 utm. C:\Documents and Settings\username\Desktop\Projects\utm\utm\Web References\AppManagerEmailer\Reference.cs の AppManagerEmailer.Emailer.AddToQueue(String txtFrom, String txtTo, String txtSubject, String txtBody, Int32 intAppId, Boolean blnIsBodyHtml) :93 utm.test.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\username\Desktop\Projects\utm\utm\test.aspx.cs:23 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp、オブジェクト o、オブジェクト t、EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy。Callback(オブジェクト送信者、EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

バージョン情報: Microsoft .NET Framework バージョン:2.0.50727.3053; ASP.NET バージョン:2.0.50727.3053

prod 上のアプリがテスト上の ws を指している場合、それは機能します。また、テストのアプリが本番の ws を指している場合、それは機能します。

面白いので、別のアプリで ws on prod を使ってみました。元のアプリと同じように動作しました。

また、正常に動作する製品で実行されている他の Web サービスがあります。これは、問題を引き起こしていると思われる唯一のものです。

私がアプリで使用するコードを次に示します。

Emailer e = new Emailer();
e.Credentials = System.Net.CredentialCache.DefaultCredentials;
int intEmailId = e.AddToQueue(fromEmail, toEmail, subject, body, 103, true);

私のWebサービスのコードは次のとおりです。

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Net.Mail;
using System.Collections.Generic;

namespace AppManager.WebServices
{
    /// <summary>
    /// Summary description for emailer
    /// </summary>
    [WebService(Namespace = "http://www.mydomain.com/apps/appManager/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Emailer : System.Web.Services.WebService
    {
        [WebMethod]
        public int AddToQueue(string txtFrom, string txtTo, string txtSubject, string txtBody, int intAppId, bool blnIsBodyHtml)
        {
            Email e = new Email()
            {
                From = new MailAddress(txtFrom),
                Subject = txtSubject,
                Body = txtBody,
                IsBodyHtml = blnIsBodyHtml,
                AppId = intAppId
            };
            e.To.Add(txtTo);
            e.AddToQueue();

            return e.Id;
        }

    }
}

では、何が問題になると思いますか?

4

2 に答える 2

1

2 つのサーバーの構成の違いのように思えます。

とはいえ、この KB http://support.microsoft.com/kb/896861を確認することをお勧めします。

Microsoft は、FQDN が正確に一致しない場合に 401.1 エラーが発生する可能性のあるループバック保護コードをいくつか追加しました。

システムのイベント ビューアをチェックして、さらに詳細があるかどうかを確認します。

于 2009-12-28T15:02:06.590 に答える
0

System.Net.CredentialCache.DefaultNetworkCredentialsを使用する必要があると思います。テストで機能する理由について、テストで Windows 統合認証が必要であり、匿名アクセスが許可されていないことを確認しましたか?

于 2009-12-28T14:58:53.117 に答える