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