2009-12-28 195 views
2

我有兩臺相同的服務器。 Win2k3。我有一個Web服務將電子郵件和使用該服務的應用程序排隊。兩者都使用相同的文件夾結構,權限和IIS設置在兩臺機器上進行託管。一個叫做「測試」,另一個叫做「prod」。Web服務在一臺服務器上失敗(401未授權),但在另一臺服務器上失敗

理想情況下,prod上的應用程序將指向產品上的ws。但是,如果是這樣的話,我碰到下面的錯誤頁面:

Server Error in '/Apps/UTMv1' Application.

The request failed with HTTP status 401: Unauthorized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[WebException: The request failed with HTTP status 401: Unauthorized.]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +431201 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204 utm.AppManagerEmailer.Emailer.AddToQueue(String txtFrom, String txtTo, String txtSubject, String txtBody, Int32 intAppId, Boolean blnIsBodyHtml) in C:\Documents and Settings\username\Desktop\Projects\utm\utm\Web References\AppManagerEmailer\Reference.cs: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, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, 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

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

如果對測試WS上PROD點的應用程序,它的工作原理。另外,如果測試中的應用程序指向了產品上的ws,它就可以工作。

爲了好玩,我試着在另一個應用程序中使用ws。它的表現與原始應用程序相同。

此外,我有其他的Web服務運行prod上正常工作。這是唯一導致問題的原因。

這是我在應用程序中使用新的向上郵件器和隊列的郵件代碼:

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; 
     } 

    } 
} 

那麼,做什麼你認爲可能是問題?

+0

聽起來像那裏可能是一個配置問題。如果沒有答案解決您的問題,請嘗試發佈到serverfault。 – 2009-12-28 15:01:33

回答

1

這聽起來像是兩臺服務器之間的配置差異。

這就是說,你可能想看看這個KB http://support.microsoft.com/kb/896861

微軟添加了一些迴環保護代碼,可能導致錯誤401.1如果FQDN的不完全匹配。

檢查您的系統事件查看器,看看是否有更多的細節。

+1

事件查看器顯示每個401錯誤的Web事件。除了Web事件顯示已驗證用戶的用戶名和線程帳戶名(始終爲「NT AUTHORITY/NETWORK SERVICE」)外,它與錯誤頁基本上具有相同的信息。它還說「假冒」是錯誤的。 – 2009-12-28 18:04:23

+0

我剛剛嘗試了以下事情(但沒有更改):1)將「Network Service」用戶添加到WS上的文件夾權限。 2)使用用戶名,密碼和域將defaultCredentials更改爲硬編碼的netcredentials。 3)將「」添加到應用程序web.config的system.web部分。 – 2009-12-28 18:07:23

+0

它看起來不像KB根據標準適用。 – 2009-12-28 18:10:45

0

我相信你需要使用System.Net.CredentialCache.DefaultNetworkCredentials。至於它爲什麼在測試中起作用,您是否檢查過該測試是否需要Windows集成身份驗證,並且不允許匿名訪問?

+0

我嘗試了DefaultNetworkCredentials以及相同的結果。正如我上面所說的,兩臺服務器的IIS設置是相同的(包括目錄安全性)。匿名訪問被禁用並啓用集成的Windows身份驗證。 – 2009-12-28 17:15:10

相關問題