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;
}
}
}
では、何が問題になると思いますか?