Web 服务在一台服务器上失败(401 未经授权),但在另一台服务器上没有失败

发布于 2024-08-15 17:41:16 字数 3381 浏览 6 评论 0原文

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

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

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

请求失败,状态为 HTTP 401:未经授权。描述:安 期间发生未处理的异常 当前网络的执行 要求。请检查堆栈跟踪 有关错误的更多信息 以及它在代码中的起源。

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

来源错误:

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

堆栈跟踪:

[WebException:请求失败 HTTP 状态 401:未经授权。]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 消息、WebResponse 响应、流 响应流、布尔值 asyncCall) +431201 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(字符串 方法名称,对象[]参数)+204 utm.AppManagerEmailer.Emailer.AddToQueue(字符串 txtFrom,字符串 txtTo,字符串 txtSubject、字符串 txtBody、Int32 intAppId、布尔值 blnIsBodyHtml) 中 C:\文件和 设置\用户名\桌面\项目\utm\utm\Web 参考文献\AppManagerEmailer\Reference.cs:93 utm.test.Page_Load(对象发送者, EventArgs e) 在 C:\Documents 中并且 设置\用户名\桌面\项目\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(布尔值 includeStagesBeforeAsyncPoint,布尔值 includeStagesAfterAsyncPoint) +627

版本信息:Microsoft .NET 框架版本:2.0.50727.3053; ASP.NET版本:2.0.50727.3053

如果产品上的应用程序指向测试上的 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);

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

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

    }
}

那么,您认为可能是什么问题?

I have two identical servers. Both Win2k3. I have a web service that queues emails and an application that consumes that service. Both are hosted on both machines using identical folder structures, permissions, and IIS settings. One is called "test" and the other "prod".

Ideally, the app on prod will point to the ws on prod. However, when that is the case, I get the following error page:

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

If the app on prod points to the ws on test, it works. Also, if the app on test points to the ws on prod, it works.

For fun, I tried using the ws on prod in another app. It behaved the same as the original app.

Also, I have other web services running on prod that work properly. This is the only one that seems to be causing problems.

Here's the code I use in the app to new-up the emailer and queue an email:

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

Here's the code for my web service:

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

    }
}

So, what do you think could be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女中豪杰 2024-08-22 17:41:16

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

也就是说,您可能需要查看此知识库 http://support.microsoft.com/kb/896861

Microsoft 添加了一些环回保护代码,如果 FQDN 不完全匹配,则可能会导致 401.1 错误。

检查您的系统事件查看器以查看是否有更多详细信息。

It really sounds like a configuration difference between the two servers.

That said, you may want to check out this KB http://support.microsoft.com/kb/896861

Microsoft added some loopback protection code that could result in a 401.1 error if FQDN's don't match exactly.

Check your system Event Viewer to see if there are any more details.

莫多说 2024-08-22 17:41:16

我相信您需要使用 System.Net.CredentialCache .DefaultNetworkCredentials。至于为什么它在测试中起作用,您是否检查过测试需要Windows集成身份验证并且不允许匿名访问?

I believe that you need to use System.Net.CredentialCache.DefaultNetworkCredentials. As to why it works on test, have you checked to see that test is requiring Windows Integrated authentication and doesn't allow anonymous access?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文