I'm trying to retrieve a list of contacts from CRM 4.0 but I'm having problems authenticating. From what I've read, the method of listing all clinets is to parse the XML returned from an ExportAllXmlRequest
The problem is, when I browse to http://crmserver/MSCRMServices/2007/spla/CRMDiscoveryService.asmx, I get a 401.2 unauthorized and no prompt to authenticate. If I add the web reference via visual studio, I get a password prompt which doesn't accept my credentials. I've also tried authenticating in code with the following, but neither work. Windows Authentication and Anonymous Authentication are both enabled on the server.
CrmService svc = new CrmService();
// this doesn't work
svc.UseDefaultCredentials = true;
// this doesn't work either
svc.Credentials = new NetworkCredential("myuser", "password", "mydomain");
svc.Credentials= System.Net.CredentialCache.DefaultCredentials;
ExportAllXmlRequest request = new ExportAllXmlRequest();
ExportAllXmlResponse response = (ExportAllXmlResponse)svc.Execute(request);
string resp=string.Empty;
using (StreamReader reader = new StreamReader(response.ExportXml)) {
resp = reader.ReadToEnd();
}
return resp;
Is there 1) An easier method of listing contacts from CRM and 2) something I can do to fix this authentication issue.