2

我有两台相同的服务器。都是win2k3。我有一个将电子邮件排队的 Web 服务和一个使用该服务的应用程序。两者都使用相同的文件夹结构、权限和 IIS 设置托管在两台计算机上。一个称为“测试”,另一个称为“产品”。

理想情况下,prod 上的应用程序将指向 prod 上的 ws。但是,在这种情况下,我会收到以下错误页面:

“/Apps/UTMv1”应用程序中的服务器错误。

请求失败,HTTP 状态为 401:未授权。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Net.WebException:请求失败,HTTP 状态 401:未授权。

源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪:

[WebException:请求失败,HTTP 状态 401:未授权。]
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) 在 C:\Documents and Settings\username\Desktop\Projects\utm\utm\Web References\AppManagerEmailer\Reference.cs :93 utm.test.Page_Load(Object sender, EventArgs e) 在 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。回调(对象发送者,EventArgs e)+35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +627

版本信息:Microsoft .NET Framework 版本:2.0.50727.3053;ASP.NET 版本:2.0.50727.3053

如果 prod 上的应用程序指向测试中的 ws,它就可以工作。此外,如果测试上的应用程序指向产品上的 ws,它就可以工作。

为了好玩,我尝试在另一个应用程序中使用 ws on prod。它的行为与原始应用程序相同。

此外,我还在 prod 上运行了其他可以正常工作的 Web 服务。这是唯一一个似乎引起问题的问题。

这是我在应用程序中使用的代码来更新电子邮件和排队电子邮件:

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

这是我的网络服务的代码:

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

这听起来确实像是两台服务器之间的配置差异。

也就是说,您可能想查看此知识库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 回答