title: Web service fails (401 Unauthorized) on one server but not on the other
body: <p>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".</p>
  
  <p>Ideally, the app on prod will point to the ws on prod. However, when that is the case, I get the following error page:</p>
  
  <blockquote>
    <p>Server Error in '/Apps/UTMv1'
    Application.</p>
    
    <p>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. </p>
    
    <p>Exception Details:
    System.Net.WebException: The request
    failed with HTTP status 401:
    Unauthorized.</p>
    
    <p>Source Error: </p>
    
    <p>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.  </p>
    
    <p>Stack Trace: </p>
    
    <p>[WebException: The request failed with
    HTTP status 401: Unauthorized.]<br>
    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<br>
    System.Web.UI.Control.OnLoad(EventArgs
    e) +99<br>
    System.Web.UI.Control.LoadRecursive()
    +50    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean
    includeStagesAfterAsyncPoint) +627</p>
    
    <p>Version Information: Microsoft .NET
    Framework Version:2.0.50727.3053;
    ASP.NET Version:2.0.50727.3053</p>
  </blockquote>
  
  <p>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. </p>
  
  <p>For fun, I tried using the ws on prod in another app. It behaved the same as the original app.</p>
  
  <p>Also, I have other web services running on prod that work properly. This is the only one that seems to be causing problems.</p>
  
  <p>Here's the code I use in the app to new-up the emailer and queue an email:</p>
  
  <pre><code>Emailer e = new Emailer();
  e.Credentials = System.Net.CredentialCache.DefaultCredentials;
  int intEmailId = e.AddToQueue(fromEmail, toEmail, subject, body, 103, true);
  </code></pre>
  
  <p>Here's the code for my web service:</p>
  
  <pre><code>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
  {
      /// &lt;summary&gt;
      /// Summary description for emailer
      /// &lt;/summary&gt;
      [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;
          }
  
      }
  }
  </code></pre>
  
  <p>So, what do you think could be the problem?</p>