web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

The request failed with HTTP status 401: Unauthorized. While rendering SSRS report from workflow.

(0) ShareShare
ReportReport
Posted on by 7,755

Hi Guys,

I am getting 401 error while rendering report from workflow, This Report is working fine on report server and in CRM . I am getting this error  from last two days and before that every thing was fine. I have checked every thing in report server and it's configuration but did not get any luck. Below is detailed error and workflow code.

Error:

Workflow suspended temporarily due to error: Unhandled Exception: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)   at Workflow.ReportService.ReportExecutionService.LoadReport(String Report, String HistoryID) at ReportGenerate.GenerateReport(String accountId, String finanicalyearId, String accountName, EntityReference reportId, String reportServiceUrl, IWorkflowContext wfContext, ITracingService tracer) at Execute(CodeActivityContext executionContext) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Below is code for rendering report:

ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

rs.Url = reportServiceUrl;

byte[] result = null;

string reportPath = string.Format("/{0}_MSCRM/CustomReports/{1}", wfContext.OrganizationName, reportId.Id.ToString("B"));

tracer.Trace("report path: {0}; ", reportPath);
string format = "Excel";
string historyID = null;
string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "accountId";
parameters[0].Value = accountId;
string encoding;

string mimeType;
string extension;
Warning[] warnings = null;

string[] streamIDs = null;

ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;

execInfo = rs.LoadReport(reportPath, historyID);

if (execInfo.CredentialsRequired)
{
List<DataSourceCredentials> dsCredentials = new List<DataSourceCredentials>();
foreach (DataSourcePrompt dsp in execInfo.DataSourcePrompts)
{
DataSourceCredentials credentials1 = new DataSourceCredentials();
credentials1.DataSourceName = dsp.Name;
tracer.Trace("; DataSourceName: " + credentials1.DataSourceName);
credentials1.UserName = wfContext.InitiatingUserId.ToString();
tracer.Trace("; username: " + wfContext.InitiatingUserId.ToString());
credentials1.Password = wfContext.OrganizationId.ToString();
tracer.Trace("; pword: " + wfContext.OrganizationId.ToString());
dsCredentials.Add(credentials1);
}
execInfo = rs.SetExecutionCredentials(dsCredentials.ToArray());
}

rs.SetExecutionParameters(parameters, "en-us"); // en-us
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
tracer.Trace("Attempting the render; ");

result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

Please help. Thanks

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hello, welcome to community !

    Did you really verified the user used in integration is correct ? (System.Net.CredentialCache.DefaultCredentials)

    401 - Unauthorized is user without permission to execute determined action in the system.

    I suggested you see all call in your application that sent request authenticated, and that ensure it's user have be permission.

    Thank you & Regards !

    I hope helpful you !

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Workflow is getting execute under admin user context that has system admin role.

    I have also tried with network credentials but it did not resolve my issue.

  • Community Member Profile Picture
    on at

    This user admin he're added within the users of implementation of CRM Dynamics ?

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    What do you mean by users of implementation?

    Do you mean service account or deployment admin?

  • Community Member Profile Picture
    on at

    If your Dynamics CRM be OnPremises

    social.technet.microsoft.com/.../31429.configurando-o-gerenciador-de-implantacao-dynamics-crm.aspx

    See it link, the image of application: "Dynamics CRM Deployment Manager".

  • Dynamics365 Rocker Profile Picture
    7,755 on at

    Yes that user is deployment admin as well.

  • talk2.gauravb Profile Picture
    120 on at

    Hi,

    Have you verified the execution user is added in CRM report user group. Can you try to add below logic in your code and check its working or not.

     rs.Credentials =new System.Net.NetworkCredential("UserName","Password","DomainName"); instead of rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at

    This issue has been auto resolved after few days.

    After that we were getting different error as below:

    There are multiple root elements. Line 1, position 99.

    This error was related to parameters.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans