locked
The request failed with HTTP status 401: Unauthorized. RRS feed

  • Question

  • This error is occurring. What can be?
     
    The request failed with HTTP status 401: Unauthorized.
     
    this code:

     

    CrmService _svc = new CrmService();

    _svc.Url = http://localhost/mscrmservices/2006/crmservice.asmx;

    _svc.Credentials = System.Net.CredentialCache.DefaultCredentials;

    _svc.UseDefaultCredentials = true;

    QueryByAttribute query = new QueryByAttribute();

    query.ColumnSet = new AllColumns();

    query.EntityName = EntityName.task.ToString();

    query.Attributes = new string[] { "ActivityId" };

    query.Values = new string[] { "2ff5d1c9-fd79-403e-9785-a9ca46aa1886" };

    BusinessEntityCollection results = _svc.RetrieveMultiple(query);

    if (results.BusinessEntities.Length > 0)

    {

     task Task = (task)results.BusinessEntities[0];

    Task.new_repasse.Value = Convert.ToBoolean(RadioButtonListRepasse.SelectedValue);

     

     _svc.Update(Task);

    }

    Thursday, December 20, 2007 5:27 PM

Answers

  • Ok,

    I don't know about the 401 error but the problem you are encountering is related to not naming the condition attribute correctly.

    CRM is case sensitive it will cause an error if you don't name the attribute correctly.

    Instead of "ActivityID" try "activityid".

    I just ran the code it seems to work fine.

    Furthermore if you want to be able to catch this error try doing the following.

    Errors will be given in detail within the Detail property, which happens to be an XMLNode so simply calling the InnerText shows you what you need.

    Code Block

    try

    {

     //Your data operation here.

    }

    catch (System.Web.Services.Protocols.SoapException ex)

    {

    Console.WriteLine(ex.Detail.InnerText);

     

     }

     

     

     

    Hope that helps

     

    Oshri Cohen
    http://mymscrm3.blogspot.com/
    http://www.linkedin.com/in/oshricohen

     

     

    Monday, December 24, 2007 2:30 PM

All replies

  •  

    If you are running this code on the server.

    Make sure to also specify the port number, CRM 3.0 usually runs on port 5555 be default so your url should be:
    http://localhost:5555/mscrmservices/2006/crmservice.asmx

     

    otherwise if that doesn't work maybe the user you are logging in with does not have permission to use CRM in that case specify the the user by doing this.

    _svc.Credentials = new System.Net.NetworkCredentials("user","Password","domain");

    Hope that helps.

    Oshri Cohen
    http://mymscrm3.blogspot.com/
    http://www.linkedin.com/in/oshricohen
    Thursday, December 20, 2007 6:49 PM
  •  

    hi,

     

    this code's sample works for a customized entity but an error occor when i use it in tasks. there is any restriction for this kind of entity?

    Friday, December 21, 2007 5:36 PM
  • Ok,

    I don't know about the 401 error but the problem you are encountering is related to not naming the condition attribute correctly.

    CRM is case sensitive it will cause an error if you don't name the attribute correctly.

    Instead of "ActivityID" try "activityid".

    I just ran the code it seems to work fine.

    Furthermore if you want to be able to catch this error try doing the following.

    Errors will be given in detail within the Detail property, which happens to be an XMLNode so simply calling the InnerText shows you what you need.

    Code Block

    try

    {

     //Your data operation here.

    }

    catch (System.Web.Services.Protocols.SoapException ex)

    {

    Console.WriteLine(ex.Detail.InnerText);

     

     }

     

     

     

    Hope that helps

     

    Oshri Cohen
    http://mymscrm3.blogspot.com/
    http://www.linkedin.com/in/oshricohen

     

     

    Monday, December 24, 2007 2:30 PM
  • Hi,

    Used to try cath and the error is:
     
    The object cannot be updated because it is read-only. Platform
     
    What can be?
     
     

     

    Thursday, December 27, 2007 10:15 AM
  • It could be that the specific record you are trying to edit has been closed/completed.
    In either case CRM prohibits any further modifications.
    Also if you are impersonating a user that does not have any write rights to that record, the same error will show up.

    Oshri Cohen
    http://mymscrm3.blogspot.com/
    http://www.linkedin.com/in/oshricohen
    Thursday, December 27, 2007 1:47 PM