i need to create plugin which retrieve records in CRM Online. This plugin will be registered on Dynamics CRM 365 On-Premise. I've trying all i know to create this plugin, also searching the tutorial on the internet. But, everytime i tested the plugin. It's always says
"Metadata contains reference that cannot be resolved https://office.api.crm5.dynamics.com/XRMServices/2011/Organization.svc".
After getting this error for the first time, i check wether the link above is searcable inside my pc. And i'm sure that the link is searchable. To connect CRM Online through CRM 365 plugin. I use this code:
private static void ConnectToMSCRM()
{
try
{
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = "[email protected]";
credentials.UserName.Password = "crmpass";
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
Uri serviceUri = new Uri("https://office.api.crm5.dynamics.com/XRMServices/2011/Organization.svc");
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);
proxy.EnableProxyTypes();
And on the other side, i write this to check if i can connect to CRM online or not:
IPluginExecutionContext context = (IPluginExecutionContext)serprov.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serfac = (IOrganizationServiceFactory)serprov.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serfac.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity ent = (Entity)context.InputParameters["Target"];
// presaledid = ent.GetAttributeValue<String>("new_presalesid");
try
{
ConnectToMSCRM();
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
Guid userid = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).UserId;
if (userid != Guid.Empty)
return;
Those code returning error message. Meta data contain references that cannot be resolved. Strangely, when i use the same code inside console application, i'm able to connect with CRM Online. I am a bit frustation with this. Almost 5 days still dont get the solution. If you have an advice for me to fix the error. Please tell me :)
Also i have another condition while tested this plugin. I am on the client office. To access CRM 365 On-Premise, they provide me an username and password to connect the Wi-fi. While connecting this wi-fi. I am able to access CRM 365 On-premise. But i'm unable to connect CRM Online (no internet access). Meanwhile, inside my plugin code, i must connect to CRM Online to get the records. Because when i success to connect using console application, i use my personal wifi with internet connection. Is that the source of this problem ?