locked
CRM Webservice not working. Error: The request failed with HTTP status 401: Unauthorized RRS feed

  • Question

  • Hi,

    I am running one of the SDK .net vb program (SDK\Server\FullSample\DataBinding Project). I changed the Url, Organization name, etc., according to the instructions specified in the readme file in SDK. But I am getting error while i am running "the request failed with HTTP status 401: Unauthorized"

    Kindly let me know if you have any ideas or anybody got the same problem.

    Thanks,

    NAG.
    Sunday, August 9, 2009 8:36 AM

Answers

  • This is strange, May be trust for delegation is enabled for your new CRM Server (Server B) and not for other Server (CRM A). can u tell which domain the other  pc is in. Can you run your code from any machine on that domain (not the crm machine).
    Monday, August 10, 2009 1:55 PM

All replies

  • Hi Nag,
    Are you running the sample on the MS CRM Server or some other machine. I am asking because normally 401 Error Happens when you try to call the CRM Sdk from other server. Just check whether the same sample is running on MS CRM Server and not running on the client. If this is the case, then it is a double hop problem and you have to enable trust for delegation. here is a very good post on msdn blog for this explanning double hop problem and its solution.

    http://blogs.msdn.com/crm/archive/2009/01/14/trust-for-delegation-in-list-web-part-for-microsoft-dynamics-crm-4-0.aspx

    Other than that i didn't see any problem with the code.
    I hope it helps.
    Sunday, August 9, 2009 8:57 AM
  • Hi,

    Thanks for the quick reply. Yes I am running this code from other computer. And when i am adding the webservice i am giving administrator user name and passoword.  And also i am able to access the webservice on the browser.

    BR,

    NAG.
    Sunday, August 9, 2009 9:50 AM
  • Try running the same code on the MS CRM server and see if it works. I was facing teh same problem in a project where the code was running on the CRM server and not on the client machine, until i came across the double hop authentication problem and its solution as specified in teh above msdn blog post.
    Sunday, August 9, 2009 10:13 AM
  • Hi,
    The post is called CRM Web Service and DNS.
    It may help.
    Sunday, August 9, 2009 10:28 AM
  • Hi,

    It's running on the server without any problems.. but from my pc it's giving the same error..
    Sunday, August 9, 2009 11:05 AM
  • Hmmm,

    Just out of  curiosity but just check  if the URL is pointing to the right server

    // TODO Replace 'localhost:5555' with your CRM server information.

    service.Url =

    @"http://localhost:5555/MSCRMServices/2007/CrmService.asmx";

    i mean by mistake, it is not localhost. Anyway if that is not  the case the your  problem is defintely double hop. I would suggest you ask your network guys to implement trust for delegation and create a trust between the domain.  The article i sent you earlier gave some tips on how to do it.

    Also do one more thing,
    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    replace the above line with this line giving the  username, password and domain of the MS CRM Server.

    service.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

    I think it will work. If that is the case than i am almost 100% sure that your pc is having problem in delegating and your network guy has to enable  the trust for delegation on the server.

     Also if your application is in asp.net, then it must be windows authentication  enabled, disabled anyoumous access and impersation enabled.

    Sunday, August 9, 2009 11:39 AM
  • Hi,

    Thanks again for quick reply.

    1) If i type the webservice url on my pc browser it works fine.

    2) The following try also tried. I hardcoded my user name, passowrd, domain name. The problem is same.

    service.Credentials = new System.Net.NetworkCredential("username", "password", "domain");

    I think it must be related to the delegating network. Here one more doubt, My pc is not on the domain. does it cause this problem ?

    Regards,

    nag
    Sunday, August 9, 2009 12:04 PM
  • Hmmm, that could be the problem, may be if you add your pc to the domain it will solve your problem.

    Sunday, August 9, 2009 12:06 PM
  • Hi,

    I have one more CRM instance in another server. I changed the url in the same SDK program and running from my PC, I am able to access the data through the webservice without any problems.  But still my pc is not in the domain. I don't think this is not the case. Any idea?

    NAG.
    Monday, August 10, 2009 10:13 AM
  • This is strange, May be trust for delegation is enabled for your new CRM Server (Server B) and not for other Server (CRM A). can u tell which domain the other  pc is in. Can you run your code from any machine on that domain (not the crm machine).
    Monday, August 10, 2009 1:55 PM