The request failed with HTTP status 401: Unauthorized. in

yuhe
Member Posts: 2
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
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
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions