Hello All,
I am using D365 online, here i have a requirement to consume web API within a plugin. I have tried with below code -
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential("TestUser@xyz.com", "Test");
client.UseDefaultCredentials = true;
byte[] responseBytes = client.DownloadData(new Uri("">mywebapi.azurewebsites.net/.../"));
AccountNo = Encoding.UTF8.GetString(responseBytes);
tracer.Trace("AccountNo= " + AccountNo);
}
tracer.Trace("SAPAccountNo= " + SAPAccountNo);
Error message -
rror Message:
Unhandled exception:
Exception type: Microsoft.Crm.CrmException
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): SyncToSAP.Plugins.PostAccountCreate: System.Net.WebException: The remote server returned an error: (404) Not Found.
at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.<>c__DisplayClass24_0.<Execute>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.CDSExecute(IServiceProvider serviceProvider)
at Microsoft.Crm.Asynchronous.EventOperation.InvokePlugin(AsyncExecutionContext context, IPlugin pluginInstance)
-- End stack trace --
Can anyone please suggest me whats wrong i am doing here .