locked
custom page Web reference problem RRS feed

Answers

  • I have no idea if the code in the link works for CRM 4.0, however now that I'm back at work I can confirm that I used a different Web Service class when generating PDF reports from a Custom Workflow Activity.  See if my code works for you:

    				ReportExecutionService res = new ReportExecutionService();
    				res.Url = String.Format("{0}/ReportExecution2005.asmx", MrCRM.Utils.Registry.GetStringValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM", "SQLRSServerURL"));
            res.Credentials = new System.Net.NetworkCredential(userName, password, domain);
    				res.PreAuthenticate = true;
    				res.UnsafeAuthenticatedConnectionSharing = true;
    
    				// build report request
    				string reportPath = String.Format(@"/{0}_MSCRM/{1}", organisationName, reportName);
    				string format = "PDF";
    				string historyID = null;
    				string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
    
    				ParameterValue[] parameters = new ParameterValue[1];
    				parameters[0] = new ParameterValue();
    				parameters[0].Name = String.Format(@"CRM_Filtered{0}", primaryEntitySchemaName);
    				parameters[0].Value = String.Format(@"select {0}0.* from Filtered{1} as {0}0 where ({0}0.{0}id='{2}')", context.PrimaryEntityName, primaryEntitySchemaName, context.PrimaryEntityId.ToString());
    
    				string encoding;
    				string mimeType;
    				string extension;
    				Warning[] warnings = null;
    				string[] streamIDs = null;
    
    				ExecutionInfo execInfo = new ExecutionInfo();
    				ExecutionHeader execHeader = new ExecutionHeader();
    
    				res.ExecutionHeaderValue = execHeader;
    
    				execInfo = res.LoadReport(reportPath, historyID);
    
    				res.SetExecutionParameters(parameters, "en-au");
    				String SessionId = res.ExecutionHeaderValue.ExecutionID;
    
    				try
    				{
    					result = res.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
    
    					execInfo = res.GetExecutionInfo();
    				}
    				catch (SoapException ex)
    				{
    					throw new InvalidPluginExecutionException(
    						String.Format("Error executing ReportService.Render in the {0} plug-in.",
    							this.GetType().ToString()),
    							ex);
    				}
    
    

    The Web Service URL I used to generate my Web Service proxy was:

    http://<reportserver>/ReportServer/ReportExecution2005.asmx

     


    --pogo (pat)
    • Marked as answer by verystupidguy Monday, April 11, 2011 2:26 AM
    Sunday, April 10, 2011 11:01 PM

All replies

  • You aren't referencing the namespace that the ReportingService reference was created under.  You either need to include the applicable "using" statement at the top of your class file, or reference the fully qualified name of the class.  To do either:

    1. Right-click on ReportingService
    2. Select 'Resolve'
    3. Select either option - the first (from memory) will add the applicable "using" statement, the second will alter the class reference to be fully qualified

    --pogo (pat)
    Friday, April 8, 2011 11:30 AM
  • i changed the report service web reference to 2010 since the report server is sql2008 r2.

    i have tried to replace the error sentence

    ReportingService2010 rs = new ReportingService2010();

    however rs.Render contained error because this class doesn't contained the function Render.

    then tried to add the web reference http://ServerName/ReportServer/ReportExecution2005.asmx?wsdl.

    i found that ReportExecution2005 rs = new ReportExecution2005();

    contained the function Render but it doesn't take 12 arguments.

    i wanna ask if this article  http://gustafwesterlund.blogspot.com/2007/01/how-to-create-crm-email-with-report.html really work in crm 4.0 about create pdf,create email and send email?

    thanks

    Sunday, April 10, 2011 7:42 AM
  • I have no idea if the code in the link works for CRM 4.0, however now that I'm back at work I can confirm that I used a different Web Service class when generating PDF reports from a Custom Workflow Activity.  See if my code works for you:

    				ReportExecutionService res = new ReportExecutionService();
    				res.Url = String.Format("{0}/ReportExecution2005.asmx", MrCRM.Utils.Registry.GetStringValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM", "SQLRSServerURL"));
            res.Credentials = new System.Net.NetworkCredential(userName, password, domain);
    				res.PreAuthenticate = true;
    				res.UnsafeAuthenticatedConnectionSharing = true;
    
    				// build report request
    				string reportPath = String.Format(@"/{0}_MSCRM/{1}", organisationName, reportName);
    				string format = "PDF";
    				string historyID = null;
    				string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
    
    				ParameterValue[] parameters = new ParameterValue[1];
    				parameters[0] = new ParameterValue();
    				parameters[0].Name = String.Format(@"CRM_Filtered{0}", primaryEntitySchemaName);
    				parameters[0].Value = String.Format(@"select {0}0.* from Filtered{1} as {0}0 where ({0}0.{0}id='{2}')", context.PrimaryEntityName, primaryEntitySchemaName, context.PrimaryEntityId.ToString());
    
    				string encoding;
    				string mimeType;
    				string extension;
    				Warning[] warnings = null;
    				string[] streamIDs = null;
    
    				ExecutionInfo execInfo = new ExecutionInfo();
    				ExecutionHeader execHeader = new ExecutionHeader();
    
    				res.ExecutionHeaderValue = execHeader;
    
    				execInfo = res.LoadReport(reportPath, historyID);
    
    				res.SetExecutionParameters(parameters, "en-au");
    				String SessionId = res.ExecutionHeaderValue.ExecutionID;
    
    				try
    				{
    					result = res.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
    
    					execInfo = res.GetExecutionInfo();
    				}
    				catch (SoapException ex)
    				{
    					throw new InvalidPluginExecutionException(
    						String.Format("Error executing ReportService.Render in the {0} plug-in.",
    							this.GetType().ToString()),
    							ex);
    				}
    
    

    The Web Service URL I used to generate my Web Service proxy was:

    http://<reportserver>/ReportServer/ReportExecution2005.asmx

     


    --pogo (pat)
    • Marked as answer by verystupidguy Monday, April 11, 2011 2:26 AM
    Sunday, April 10, 2011 11:01 PM
  • hey , thanks for the code, now i am able to generate report pdf now,  however i dont understand how i can add parameters of report when i am trying to create Default Order report of CRM pdf.

    i checked by sql database query and it can generate neccessary information by setting the salesorderid.

    i wanna ask how can set the parameter ? i tried Salesorder as 'primaryEntitySchemaName', but the report (the default CRM order report) doesn't contained this parameters. i checked the report rdl in studio but i cant see any parameters that is about restricting the report information.


    parameters[0].Name = String.Format(@"CRM_Filtered{0}", primaryEntitySchemaName);
    parameters[0].Value = String.Format(@"select {0}0.* from Filtered{1} as {0}0 where ({0}0.{0}id='{2}')", context.PrimaryEntityName, primaryEntitySchemaName, context.PrimaryEntityId.ToString());

    how can i modify the above line in order to fit the default order report that only generate one record base on Salesorderid (the order entity GUID)?

    thanks

    Monday, April 11, 2011 9:48 AM
  • Ye, I haven't tried this yet, but the following should help.

    The 'Order' report uses Automatic Filtering.  This is accomplished in a CRM Report by defining a dataset wherein the Entity table is aliased in a special way; for instance:

    SELECT   TOP (20) salesorderid AS quoteid
    FROM     FilteredSalesOrder AS CRMAF_FilteredSalesOrder
    

    When a report for which an automatic filtering alias (CRMAF_FilteredSalesOrder) is defined, is uploaded to the CRM, the CRM creates a hidden parameter in the report that is used for pre-filtering.

    You can find the definition of this hidden parameter by looking at the definition of the report in the ReportServer database (the GUID is the entity instance identifier of the report in CRM):

     

    select Parameter from Catalog where Name = '{87B29E15-E222-DD11-892E-0003FF6D78E5}';
    

     

    For the 'Order' report, the hidden parameter is as follows:

     

    	<Parameter>
       <Name>P1</Name>
       <Type>String</Type>
       <Nullable>False</Nullable>
       <AllowBlank>False</AllowBlank>
       <MultiValue>False</MultiValue>
       <UsedInQuery>True</UsedInQuery>
       <State>MissingValidValue</State>
       <Prompt />
       <PromptUser>True</PromptUser>
       <DefaultValues>
        <Value>select salesorder0.* from FilteredSalesOrder as salesorder0 where ( salesorder0.modifiedonutc &gt;= dbo.fn_BeginOfLastXDay(GetUTCDate(), 30) and salesorder0.modifiedonutc &lt;= GetUTCDate() )</Value>
       </DefaultValues>
       <Values>
        <Value>select salesorder0.* from FilteredSalesOrder as salesorder0 where ( salesorder0.modifiedonutc &gt;= dbo.fn_BeginOfLastXDay(GetUTCDate(), 30) and salesorder0.modifiedonutc &lt;= GetUTCDate() )</Value>
       </Values>
      </Parameter>
    
    

     

    So, simply change the name of the parameter to be 'P1' and the query value to be the select statement that locates your 'salesorder':

     

    parameters[0].Name = @"P1";
    parameters[0].Value = String.Format(@"select {0}0.* from Filtered{1} as {0}0 where ({0}0.{0}id='{2}')", context.PrimaryEntityName, primaryEntitySchemaName, context.PrimaryEntityId.ToString());
    

    By the way, primaryEntitySchemaName is obtained with the following:

    // Obtain info about Primary Entity
    RetrieveEntityRequest reqEntity = new RetrieveEntityRequest();
    reqEntity.EntityItems = EntityItems.EntityOnly;
    reqEntity.LogicalName = context.PrimaryEntityName;
    
    RetrieveEntityResponse respEntity = (RetrieveEntityResponse)metaService.Execute(reqEntity);
    
    string primaryEntitySchemaName = respEntity.EntityMetadata.SchemaName;
    
    
    If you're hard-coding this, you won't need all this, but I was writing a generic solution, so it had to work everything out from the entity that was currently being processed.

     

     

     

     


    --pogo (pat)
    Tuesday, April 12, 2011 12:50 AM
  • hi, thanks for the explanation, however no luck

    parameters[0].Name = @"P1";

    the report does not contained this parameter too. i think i can hard-code the sql query too except the GUID of order, the problem is i cant find the exact parameter name for the filter

    Tuesday, April 12, 2011 2:21 AM
  • Look it up in the DB.
    --pogo (pat)
    Tuesday, April 12, 2011 2:57 AM
  • hi , for the order report parameter , it is something like (i used the sql query "select Name , Parameter from Catalog" and Name is "order" because i created a copy of default order report from 4.0 folder to root of report server becasue it required authority checking when i tried to access defaul order report in 4.0 folder)

    however after i checked the parameter in the report database, i found that the copied order report doesn't contained the P1 parameter

    it is something like this:

    <Parameters>    <UserProfileState>0</UserProfileState>    <Parameter>      <Name>CRM_FilterText</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DefaultValues>        <Value nil="True" />      </DefaultValues>      <Values>        <Value nil="True" />      </Values>    </Parameter>    <Parameter>      <Name>CRM_URL</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DefaultValues>        <Value nil="True" />      </DefaultValues>      <Values>        <Value nil="True" />      </Values>    </Parameter>    <Parameter>      <Name>CRM_FullName</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>cbDisplayChoices</Name>      <Type>Integer</Type>      <Nullable>False</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>True</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt>Select information that needs to be displayed in the Item Details area:</Prompt>      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <Dependencies>        <Dependency>CRM_URL</Dependency>        <Dependency>CRM_FullName</Dependency>        <Dependency>CRM_FilterText</Dependency>      </Dependencies>      <ValidValues>        <ValidValue>          <Value>1</Value>          <Label>Product ID</Label>        </ValidValue>        <ValidValue>          <Value>2</Value>          <Label>Unit of Measure</Label>        </ValidValue>        <ValidValue>          <Value>3</Value>          <Label>Quantity</Label>        </ValidValue>        <ValidValue>          <Value>4</Value>          <Label>Price per unit</Label>        </ValidValue>        <ValidValue>          <Value>5</Value>          <Label>Tax</Label>        </ValidValue>        <ValidValue>          <Value>6</Value>          <Label>Discount</Label>        </ValidValue>      </ValidValues>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_FormatDate</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_FormatTime</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_NumberLanguageCode</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_CalendarType</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>False</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>  </Parameters>

    and then i try to query the default order report in the 4.0 folder , it is something like


    <Parameters>    <UserProfileState>0</UserProfileState>    <Parameter>      <Name>P1</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>False</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DefaultValues>        <Value>select salesorder0.* from FilteredSalesOrder as salesorder0 where ( salesorder0.modifiedonutc &gt;= dbo.fn_BeginOfLastXDay(GetUTCDate(), 30) and salesorder0.modifiedonutc &lt;= GetUTCDate() )</Value>      </DefaultValues>      <Values>        <Value>select salesorder0.* from FilteredSalesOrder as salesorder0 where ( salesorder0.modifiedonutc &gt;= dbo.fn_BeginOfLastXDay(GetUTCDate(), 30) and salesorder0.modifiedonutc &lt;= GetUTCDate() )</Value>      </Values>    </Parameter>    <Parameter>      <Name>CRM_FilterText</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DefaultValues>        <Value nil="True" />      </DefaultValues>      <Values>        <Value nil="True" />      </Values>    </Parameter>    <Parameter>      <Name>CRM_URL</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DefaultValues>        <Value nil="True" />      </DefaultValues>      <Values>        <Value nil="True" />      </Values>    </Parameter>    <Parameter>      <Name>CRM_FullName</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>cbDisplayChoices</Name>      <Type>Integer</Type>      <Nullable>False</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>True</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt>Select information that needs to be displayed in the Item Details area:</Prompt>      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <Dependencies>        <Dependency>CRM_URL</Dependency>        <Dependency>CRM_FullName</Dependency>        <Dependency>P1</Dependency>        <Dependency>CRM_FilterText</Dependency>      </Dependencies>      <ValidValues>        <ValidValue>          <Value>1</Value>          <Label>Product ID</Label>        </ValidValue>        <ValidValue>          <Value>2</Value>          <Label>Unit of Measure</Label>        </ValidValue>        <ValidValue>          <Value>3</Value>          <Label>Quantity</Label>        </ValidValue>        <ValidValue>          <Value>4</Value>          <Label>Price per unit</Label>        </ValidValue>        <ValidValue>          <Value>5</Value>          <Label>Tax</Label>        </ValidValue>        <ValidValue>          <Value>6</Value>          <Label>Discount</Label>        </ValidValue>      </ValidValues>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_FormatDate</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_FormatTime</Name>      <Type>String</Type>      <Nullable>True</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_NumberLanguageCode</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>True</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>    <Parameter>      <Name>CRM_CalendarType</Name>      <Type>String</Type>      <Nullable>False</Nullable>      <AllowBlank>False</AllowBlank>      <MultiValue>False</MultiValue>      <UsedInQuery>True</UsedInQuery>      <State>MissingValidValue</State>      <Prompt />      <DynamicPrompt>False</DynamicPrompt>      <PromptUser>True</PromptUser>      <DynamicDefaultValue>True</DynamicDefaultValue>    </Parameter>  </Parameters>

    which is contained the P1 parameter.

    i wanna ask if i am going to use this report now instead of my copied one. is this reportpath correct

    string reportPath = String.Format(@"/oName_MSCRM/4.0/{71574a17-a42a-e011-b62e-005056c00008});

    thanks

    Tuesday, April 12, 2011 4:37 AM
  • i wanna ask if i am going to use this report now instead of my copied one. is this reportpath correct

    string reportPath = String.Format(@"/oName_MSCRM/4.0/{71574a17-a42a-e011-b62e-005056c00008});

    thanks

    Yes; assuming '{71574a17-a42a-e011-b62e-005056c00008}' is the GUID assigned to the 'Order' report entity instance, and 'oName_MSCRM' is the name of your CRM Organisation DB, that is the correct Report Path.

    The reason that the P1 parameter is missing from your copy of the report, is that it is only via the process of uploading the report through the CRM that the automatic filtering parameter is created.

    So, the P1 parameter will work for the CRM 'Order' report, but it will not work for your copy.


    --pogo (pat)
    Tuesday, April 12, 2011 4:53 AM
  • hi, i am able to find the report using

    string reportPath = String.Format(@"/oName_MSCRM/4.0/{71574a17-a42a-e011-b62e-005056c00008});

    but it shows error while rendering the report (the rs.Credentials = new System.Net.NetworkCredential(name, pw, domain); is able to access the report that is not inside the 4.0 folder but it cant render the report that inside the 4.0 folder).

    the error is this:Error during processing of ‘CRM_FullName’ report parameter. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Error during processing of ‘CRM_FullName’ report parameter.

    is it about the access right problem of NetworkCredential i used or i should use other Credentials ?

    thanks

    Tuesday, April 12, 2011 6:28 AM
  • No; it is telling you that you haven't supplied the 'CRM_FullName' parameter.  It must be mandatory.
    --pogo (pat)
    Tuesday, April 12, 2011 6:40 AM
  • hi, i can open the report that is outside 4.0 folder.  then i checked and i found that i should input a crm user SystemUserId and OrganizationId in order to open the report that is inside the 4.0 folder.

    how can i supply the value of 'CRM_FullName' parameter? i tried this

    ParameterValue[] parameters = new ParameterValue[1];
                parameters[0] = new ParameterValue();
                parameters[0].Name = @"CRM_FullName";
                parameters[0].Value = @"Jason Leung";     <== this is one of the CRM SystemUser

    the same error is still occured after i added this.

     

    Tuesday, April 12, 2011 7:09 AM