Options

The request failed with HTTP status 401: Unauthorized. in

yuheyuhe Member Posts: 2
edited 2009-05-22 in Dynamics CRM
Hi,
I am new to CRM, this is the first piece of code i developed in CRM.
I got error in the following code: The request failed with HTTP status 401: Unauthorized.

System.Net.NetworkCredential creds = new System.Net.NetworkCredential();
creds.Password = my_live_email;
creds.UserName = my_password;

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 1;
token.OrganizationName = organization_name;
CrmService service = new CrmService();
service.Url = "https://website/MSCrmServices/2007/CrmService.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = creds;

lead lead = new lead();
lead.emailaddress1 = lead_email;

RetrieveDuplicatesRequest request = new RetrieveDuplicatesRequest();
request.BusinessEntity = lead;
request.MatchingEntityName = EntityName.lead.ToString();
request.PagingInfo = new PagingInfo();

RetrieveDuplicatesResponse response = (RetrieveDuplicatesResponse)service.Execute(request);

I use a live email and password to access the CRM website. I could login from the browser without any problem.
I could see xml content of CrmServiceWsdl.asmx

But when i add the web reference of webservice. it ask me the user name and password. after that, it display list of methods in the window, but give me message "The HTML document does not contain Web service discovery information." and "add reference is grayed out and I can't add it. (see attached image)
So i download the WSDL file to the local, and add the reference from the local.

I don't know whether this cause "Unauthorized" error, could anyone tell me how to fix it if it caused by this?

If not, anybody can tell me anything wrong in the code. and how to solve the problem

Appreciate for your help
Sign In or Register to comment.