Help on "The request failed with HTTP status 401: Unauthorized"

Last post 05-01-2007 9:32 AM by dongwang. 3 replies.

Sort Posts:

  • Help on "The request failed with HTTP status 401: Unauthorized"

    04-13-2007, 9:59 AM
    • Loading...
    • dongwang
    • Joined on 02-17-2004, 5:29 AM
    • Posts 12

    When calling a web service located another win2003 server from a asp.net 1.1 application located on a win2k server, get the error message.

    web service is beening setup with windows integrated security, asp.net application is anonymouse access and could be access by http://www.domain.com/app, which try to call the web service and get the return value.

    the web service reference as follows:

     

    Dim

    s As New myWebService

    s.UnsafeAuthenticatedConnectionSharing = True

    s.PreAuthenticate =

    True

    s.RequestEncoding = System.Text.Encoding.UTF8

    Dim cache As Net.CredentialCache = New Net.CredentialCache()

    cache.Add(

    New Uri(s.Url), "Negotiate", New Net.NetworkCredential("username", "password", "domain"))

    s.Credentials = cache

    s.callmethod

    ...

    the error message is :The request failed with HTTP status 401: Unauthorized

    I have read all posts under this board about this issue and tried many times, not working. The only thing I did not try is to set web.config of web service with "<identity impersonate=true />" because the web service is belonging to its owner and can not be changed. we just have the user/pwd to access it.

    Any helps would be very appericiated.

     
  • Re: Help on &quot;The request failed with HTTP status 401: Unauthorized&quot;

    04-13-2007, 12:53 PM
    Answer
    • Loading...
    • dongwang
    • Joined on 02-17-2004, 5:29 AM
    • Posts 12

    got it works now. web service was disabled outside of AD.

     

  • Re: Help on &quot;The request failed with HTTP status 401: Unauthorized&quot;

    04-24-2007, 6:31 PM

    Hi,

     I am having the same issue and I am not able to figute out why.  This is my code?  Any thoughts?

     

    using

    System;

    using

    System.Drawing;

    using

    System.IO;

    using

    System.Web;

    using

    BREWServer.MapPointService;

    using

    System.Collections.Specialized;

    using

    System.Web.UI.HtmlControls;

    namespace

    BREWServer

    {

    /// <summary>

    /// Summary description for WebForm1.

    /// </summary>

    public class WebForm1 : System.Web.UI.Page

    {

    private void Page_Load(object sender, System.EventArgs e)

    {

     

    RenderServiceSoap renderService =

    new RenderServiceSoap();

    renderService.PreAuthenticate =

    true;

    renderService.Credentials =

    new System.Net.NetworkCredential("******","***********");

     

    ViewByScale[] myViews =

    new ViewByScale[1];

    myViews[0] =

    new ViewByScale();

    myViews[0].CenterPoint =

    new LatLong();

    NameValueCollection coll=Request.QueryString;

    String latlon = coll.GetValues("latlon")[0];

    int sep = latlon.LastIndexOf("^");

    String lat = latlon.Substring(0, sep);

    String lon = latlon.Substring(sep + 1, latlon.Length - (sep + 1));

     

    myViews[0].CenterPoint.Latitude = Double.Parse(lat) / 3106;

    myViews[0].CenterPoint.Longitude = Double.Parse(lon) / -3106;

    myViews[0].MapScale = 100000;

    MapSpecification mapSpec =

    new MapSpecification();

    mapSpec.DataSourceName = "MapPoint.NA";

    mapSpec.Views = myViews;

    MapImage[] mapImages;

    mapImages = renderService.GetMap(mapSpec);

    Context.Response.Clear();

    Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

    Context.Response.ContentType = mapImages[0].MimeData.MimeType;

    MemoryStream ms =

    new MemoryStream(mapImages[0].MimeData.Bits);

    Image i = Image.FromStream(ms);

    i.Save("c:\\brew\\btmp.png", System.Drawing.Imaging.ImageFormat.Png);

    FileStream fs =

    new FileStream("c:\\brew\\btmp.png", FileMode.Open);

    byte[] b = new byte[fs.Length];

    fs.Read(b, 0, b.Length);

    Context.Response.BinaryWrite(b);

     

    fs.Close();

    File.Delete("c:\\brew\\btmp.png");

    Context.Response.End();

    }

    #region

    Web Form Designer generated code

    override protected void OnInit(EventArgs e)

    {

    //

    // CODEGEN: This call is required by the ASP.NET Web Form Designer.

    //

    InitializeComponent();

    base.OnInit(e);

    }

     

    /// <summary>

    /// Required method for Designer support - do not modify

    /// the contents of this method with the code editor.

    /// </summary>

    private void InitializeComponent()

    {

    this.Load += new System.EventHandler(this.Page_Load);

    }

    #endregion

    }

    }

  • Re: Help on &quot;The request failed with HTTP status 401: Unauthorized&quot;

    05-01-2007, 9:32 AM
    • Loading...
    • dongwang
    • Joined on 02-17-2004, 5:29 AM
    • Posts 12

    sorry not sure of your problem. but please check:

    1. can you access your web service outside of your AD with proper user permission(anonymouse or something else)?

    2. if you are using physical path of some resource like your c:..\png, is this folder could be access by proper permission?

     

    check both of your IIS and folder level authentication. 

     

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter