Web服务在一台服务器上失败(401未授权),但在另一台服务器上失败
我有两台相同的服务器。 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) +627Version 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;
}
}
}
那么,做什么你认为可能是问题?
这听起来像是两台服务器之间的配置差异。
这就是说,你可能想看看这个KB http://support.microsoft.com/kb/896861
微软添加了一些回环保护代码,可能导致错误401.1如果FQDN的不完全匹配。
检查您的系统事件查看器,看看是否有更多的细节。
事件查看器显示每个401错误的Web事件。除了Web事件显示已验证用户的用户名和线程帐户名(始终为“NT AUTHORITY/NETWORK SERVICE”)外,它与错误页基本上具有相同的信息。它还说“假冒”是错误的。 – 2009-12-28 18:04:23
我刚刚尝试了以下事情(但没有更改):1)将“Network Service”用户添加到WS上的文件夹权限。 2)使用用户名,密码和域将defaultCredentials更改为硬编码的netcredentials。 3)将“
它看起来不像KB根据标准适用。 – 2009-12-28 18:10:45
我相信你需要使用System.Net.CredentialCache.DefaultNetworkCredentials。至于它为什么在测试中起作用,您是否检查过该测试是否需要Windows集成身份验证,并且不允许匿名访问?
我尝试了DefaultNetworkCredentials以及相同的结果。正如我上面所说的,两台服务器的IIS设置是相同的(包括目录安全性)。匿名访问被禁用并启用集成的Windows身份验证。 – 2009-12-28 17:15:10
听起来像那里可能是一个配置问题。如果没有答案解决您的问题,请尝试发布到serverfault。 – 2009-12-28 15:01:33