CRM 2011 Online via an ASP.net application does not work, same code via Console Application Works -> "Authentication Failure"-error -
i'm trying connect crm 2011 online environment. i'm able connect via "console application", when i'm trying connect via "asp.net"-application same code, doesn't work, gives me "authentication failure"-error ({"an unsecured or incorrectly secured fault received other party. see inner faultexception fault code , detail."}).
is there special need make work on "asp.net" environment. tested out several solutions found on internet, gives me same error.
a "code"-snippet of simplified code:
private static clientcredentials getdevicecredentials() { return microsoft.crm.services.utility.deviceidmanager.loadorregisterdevice(); } protected void button1_click(object sender, eventargs e) { //authenticate using credentials of logged in user; string username = "*****"; //your windows live id string password = "*****"; // password clientcredentials credentials = new clientcredentials(); credentials.username.username = username; credentials.username.password = password; credentials.windows.clientcredential = credentialcache.defaultnetworkcredentials; //this url needs updated match servername , organization environment. uri organizationuri = new uri("https://*****.crm4.dynamics.com/xrmservices/2011/organization.svc"); //this url copy setting --> developer source uri homerealmuri = null; //organizationserviceproxy serviceproxy; using (organizationserviceproxy serviceproxy = new organizationserviceproxy(organizationuri, homerealmuri, credentials, getdevicecredentials())) { iorganizationservice service = (iorganizationservice)serviceproxy; organizationservicecontext orgcontext = new organizationservicecontext(service); var theaccounts = orgcontext.createquery<account>().take(1).tolist(); response.write(theaccounts.first().name); } }
i tried several things, deleting content of "livedeviceid"-folder re-running device registration tool. weird works in "console application" not on "asp.net"-solution...
ps : able generate "context"-file via crmsvcutil.exe /url:https://org.crm4.dynamics.com/xrmservices/2011/organization.svc /o:crm.cs /u:username /p:password /di:deviceusername /dp:devicpwd
is there particular reason have
credentials.windows.clientcredential = credentialcache.defaultnetworkcredentials;
you shouldn't need line windows live authentication.
even code seems valid device registration. suggest rather call directly have
using (organizationserviceproxy serviceproxy = new organizationserviceproxy(organizationuri, homerealmuri, credentials, getdevicecredentials())) {
you try following because need register once:
clientcredentials devicecredentials; if ((crmsettings.default.deviceid == string.empty) || (crmsettings.default.devicepassword == string.empty)) { devicecredentials = microsoft.crm.services.utility.deviceidmanager.registerdevice(); } else { devicecredentials = new clientcredentials(); devicecredentials.username.username = crmsettings.default.deviceid; devicecredentials.username.password = crmsettings.default.devicepassword; } using (organizationserviceproxy serviceproxy = new organizationserviceproxy(organizationuri, homerealmuri, credentials, devicecredentials)) {
i have had issues in past "already registered" response registerdevice call.
i dump out device id , password can see if being set.
Comments
Post a Comment