Hello, everyone!
We have written a very simple web app to test connection to CRM 2011 data. Here's the part of the code that tries to get a count of Contacts in CRM Database:
ClientCredentials credentials;
OrganizationServiceProxy serviceProxy;
IOrganizationService service;
OrganizationServiceContext orgServiceContext;
public CrmConnector(string username, string password, string domain, Uri organizationUri)
{
credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential(username, password, domain);
serviceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
serviceProxy.EnableProxyTypes();
service = (IOrganizationService)serviceProxy;
}
public void GetAllPrijave()
{
if (service != null)
{
var query = new QueryExpression("contact");
query.ColumnSet = new ColumnSet(true);
EntityCollection prijave = service.RetrieveMultiple(query);
throw new InvalidPluginExecutionException("Count: " + prijave.Entities.Count);
}
}
When tested in local network, it works without any problems. Anyway, when we try to access to this web application from the internet, we get "User authentication failed!" Exception. CRM IFD works without problems, we can access crm user interface and service endpoints across the internet. From web application, we tested if service was null, and it wasn't. So everything should work, except we get "User authentication failed!" Exception from this line of code:
EntityCollection prijave = service.RetrieveMultiple(query);
Thank you all for answers! =) Here's the error screen:Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The user authentication failed!
Source Error:Line 38: var query = new QueryExpression("contact");
Line 39: query.ColumnSet = new ColumnSet(true);Line 40: EntityCollection prijave = service.RetrieveMultiple(query);Line 41: throw new InvalidPluginExecutionException("Count: " + prijave.Entities.Count);
Line 42: }
Source File: C:\-------------------------\WebApplication1\CrmConnector.cs Line:40
Stack Trace:[InvalidOperationException: The user authentication failed!]
Microsoft.Xrm.Sdk.Client.ServiceProxy`1.AuthenticateCore() +693
Microsoft.Xrm.Sdk.Client.ServiceProxy`1.Authenticate() +81
Microsoft.Xrm.Sdk.Client.ServiceProxy`1.ValidateAuthentication() +19
Microsoft.Xrm.Sdk.Client.ServiceContextInitializer`1.Initialize(ServiceProxy`1 proxy) +19
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.RetrieveMultipleCore(QueryBase query) +281
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.RetrieveMultiple(QueryBase query) +10
WebApplication1.CrmConnector.GetAllPrijave() in C:\----------------------\--------------------\WebApplication1\CrmConnector.cs:40
WebApplication1._Default.Page_Load(Object sender, EventArgs e) in C:\-----------------\------------------\WebApplication1\Default.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Server Error in '/' Application.
The user authentication failed!