none
SQL Server 2008 Reporting web service execution error when generating report in "PDF" format..

    Question

  • Hi,
    I am running my web service on window 2008 platform having sql server 2008.It was working fine recently when i was using sql server 2005 but when i started using sql server 2008 the web service giving error when it executes the render method of reporting service.Error comes like "client found response content type of 'text html' but expected 'text xml'.".I tried all the things but no success.Please advice.
    Web service am using is like this: http://localhost/ReportServer/ReportService.asmx
    For your assistance i am giving u code also:

        Private Function CreateReport(ByVal zstrReportPath As String, ByVal zstrReportParam As String, ByVal zstrReportFormat As String, ByVal zstrPDFFileName As String, ByVal zstrRunAsUserCode As String, ByVal zstrRunAsUserPwd As String) As String
            Dim strReportUserName As String
            Dim strReportUserPwd As String
            Dim strReportUserDomain As String

            strReportUserName = ConfigurationSettings.AppSettings("RSUserName")
            'MsgBox(strReportUserName)
            strReportUserPwd = ConfigurationSettings.AppSettings("RSUserPassword")
            'MsgBox(strReportUserPwd)
            strReportUserDomain = ConfigurationSettings.AppSettings("RSUserDomain")
            'MsgBox(strReportUserDomain)

            Try

                'Dim rs As New ReportingService.ReportingServiceSoapClient 
                Dim rs As New ReportingService.ReportingService
                'MsgBox(rs.ToString())

                'rs.Credentials = New System.Net.NetworkCredential(strReportUserName, strReportUserPwd, strReportUserDomain) 'System.Net.CredentialCache.DefaultCredentials
                rs.Credentials = System.Net.CredentialCache.DefaultCredentials
                'MsgBox(rs.Credentials.ToString())

                Dim objDBCredentials(0) As ReportingService.DataSourceCredentials
                objDBCredentials(0) = New ReportingService.DataSourceCredentials
                objDBCredentials(0).DataSourceName = "CR"
                'MsgBox(objDBCredentials(0).DataSourceName.ToString())
                objDBCredentials(0).UserName = zstrRunAsUserCode 'Session("UserName")
                'MsgBox(objDBCredentials(0).UserName.ToString())
                objDBCredentials(0).Password = zstrRunAsUserPwd 'Session("Password")
                'MsgBox(objDBCredentials(0).Password.ToString())
                ' Render arguments.
                Dim result As Object
                Dim reportPath As String = zstrReportPath
                'MsgBox(reportPath.ToString())
                Dim format As String = "PDF"
                Dim historyID As String = Nothing
                Dim devInfo As String = Nothing

                Dim objReportParam As Object
                Dim objTemp As Object
                Dim intNumOfParam As Integer
                Dim intCounter As Integer

                objReportParam = Split(zstrReportParam, "~")

                intNumOfParam = UBound(objReportParam)
                'MsgBox(intNumOfParam)

                ' Prepare report parameter.
                Dim parameters(intNumOfParam) As ReportingService.ParameterValue
                For intCounter = 0 To intNumOfParam
                    objTemp = Split(objReportParam(intCounter), "=")
                    parameters(intCounter) = New ReportingService.ParameterValue
                    parameters(intCounter).Name = objTemp(0)
                    parameters(intCounter).Value = Replace(Replace(objTemp(1), "%3d", "="), "%27", "'")
                Next
                Dim credentials As ReportingService.DataSourceCredentials() = objDBCredentials
                'MsgBox(credentials.Length)
                Dim showHideToggle As String = Nothing
                Dim encoding As String
                Dim mimeType As String
                Dim warnings As ReportingService.Warning() = Nothing
                Dim reportHistoryParameters As ReportingService.ParameterValue() = Nothing
                'Dim streamIDs As String() = Nothing
                Dim streamIDs As String() = Nothing
                Dim streamIDs1 As String = Nothing
                Dim sh As New ReportingService.SessionHeader
                rs.SessionHeaderValue = sh
                'MsgBox(rs.SessionHeaderValue.ToString())

                Try

                    'HttpContext.Current.Response.ContentType = "text/xml"
                    result = rs.Render(zstrReportPath, zstrReportFormat, historyID, devInfo, parameters, credentials, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)
                    'result = rs.RenderStream(zstrReportPath, zstrReportFormat, streamIDs, historyID, devInfo, parameters, encoding, mimeType)
                    'MsgBox(result.Length)
                Catch e As Web.Services.Protocols.SoapException
                    MsgBox(e.Message.ToString())
                End Try

                Try
                    Dim stream As FileStream = File.Create(zstrPDFFileName, result.Length) 'File.Create("report.mhtml", result.Length)

                    stream.Write(result, 0, result.Length)
                    stream.Close()
                Catch e As Exception
                    MsgBox(e.Message.ToString())
                End Try
            Catch ex As Exception
                MsgBox(ex.Message.ToString())
            End Try
            Return ""
        End Function

    This was the code in 2005.Now i have changed the code for 2008 given below but it still giving error:

    'On Error GoTo BatchErr
            Dim strReportUserName As String
            Dim strReportUserPwd As String
            Dim strReportUserDomain As String


            strReportUserName = ConfigurationSettings.AppSettings("RSUserName")
            'MsgBox(strReportUserName)
            strReportUserPwd = ConfigurationSettings.AppSettings("RSUserPassword")
            'MsgBox(strReportUserPwd)
            strReportUserDomain = ConfigurationSettings.AppSettings("RSUserDomain")
            'MsgBox(strReportUserDomain)

            'Try


            'Dim rs As New ReportingService.ReportingService


            Dim rs As New ReportingService.ReportingService2005
            Dim rsExec As New ReportExecution.ReportExecutionService
            'MsgBox(rs.ToString())

            rs.Credentials = New System.Net.NetworkCredential(strReportUserName, strReportUserPwd, strReportUserDomain) 'System.Net.CredentialCache.DefaultCredentials
            rsExec.Credentials = New System.Net.NetworkCredential(strReportUserName, strReportUserPwd, strReportUserDomain) 'System.Net.CredentialCache.DefaultCredentials
            'rs.Credentials = System.Net.CredentialCache.DefaultCredentials
            'MsgBox(rs.Credentials.ToString())

            'Dim objDBCredentials(0) As ReportingService.DataSourceCredentials
            Dim objDBCredentials(0) As ReportExecution.DataSourceCredentials
            'objDBCredentials(0) = New ReportingService.DataSourceCredentials
            objDBCredentials(0) = New ReportExecution.DataSourceCredentials
            objDBCredentials(0).DataSourceName = "CR"
            'MsgBox(objDBCredentials(0).DataSourceName.ToString())
            objDBCredentials(0).UserName = zstrRunAsUserCode 'Session("UserName")
            'MsgBox(objDBCredentials(0).UserName.ToString())
            objDBCredentials(0).Password = zstrRunAsUserPwd 'Session("Password")
            'MsgBox(objDBCredentials(0).Password.ToString())
            ' Render arguments.
            Dim result As Object
            Dim reportPath As String = zstrReportPath
            'MsgBox(reportPath.ToString())
            Dim format As String = "PDF"
            Dim historyID As String = Nothing
            Dim devInfo As String = Nothing
            Dim extension As String = String.Empty

            Dim objReportParam As Object
            Dim objTemp As Object
            Dim intNumOfParam As Integer
            Dim intCounter As Integer

            objReportParam = Split(zstrReportParam, "~")

            intNumOfParam = UBound(objReportParam)
            'MsgBox(intNumOfParam)
            ' Prepare report parameter.
            'Dim parameters(intNumOfParam) As ReportingService.ParameterValue
            Dim parameters(intNumOfParam) As ReportExecution.ParameterValue

            For intCounter = 0 To intNumOfParam
                objTemp = Split(objReportParam(intCounter), "=")
                'parameters(intCounter) = New ReportingService.ParameterValue
                parameters(intCounter) = New ReportExecution.ParameterValue
                parameters(intCounter).Name = objTemp(0)
                parameters(intCounter).Value = Replace(Replace(objTemp(1), "%3d", "="), "%27", "'")
            Next


            'Dim credentials As ReportingService.DataSourceCredentials() = objDBCredentials
            Dim credentials As ReportExecution.DataSourceCredentials() = objDBCredentials
            'MsgBox(credentials.Length)
            Dim showHideToggle As String = Nothing
            Dim encoding As String = Nothing
            Dim mimeType As String = Nothing
            'Dim warnings As ReportingService.Warning() = Nothing
            Dim warnings As ReportExecution.Warning() = Nothing

            'Dim reportHistoryParameters As ReportingService.ParameterValue() = Nothing
            Dim reportHistoryParameters As ReportExecution.ParameterValue() = Nothing
            Dim execHeader As New ExecutionHeader()
            Dim execInfo As New ExecutionInfo
            Dim SessionId As String

            'Dim streamIDs As String() = Nothing
            Dim streamIDs As String() = Nothing

            'Dim sh As New ReportExecution.SessionHeader
            'rs.SessionHeaderValue = sh
            'MsgBox(rs.SessionHeaderValue.ToString())
            rsExec.ExecutionHeaderValue = execHeader
            execInfo = rsExec.LoadReport(reportPath, historyID)

            'rsExec.PreAuthenticate = True

            'Dim rpt As ReportExecution.ExecutionInfo = rsExec.LoadReport(zstrReportPath, Nothing)

            rsExec.SetExecutionParameters(parameters, "en-us")
            SessionId = rsExec.ExecutionHeaderValue.ExecutionID


            Try
                'HttpContext.Current.Response.ContentType = "text/xml"
                'result = rsExec.Render(zstrReportPath, zstrReportFormat, historyID, devInfo, parameters, credentials, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)

                result = rsExec.Render(zstrReportFormat, devInfo, extension, mimeType, encoding, warnings, streamIDs)
                execInfo = rsExec.GetExecutionInfo()

                'result = rsExec.Render2(zstrReportFormat, devInfo, ReportExecution.PageCountMode.Actual, extension, mimeType, encoding, warnings, streamIDs)


                'result = rs.RenderStream(zstrReportPath, zstrReportFormat, streamIDs, historyID, devInfo, parameters, encoding, mimeType)
                'MsgBox(result.Length)
            Catch e As Web.Services.Protocols.SoapException
                MsgBox(e.Message.ToString())
            End Try

            Try
                Dim stream As FileStream = File.Create(zstrPDFFileName, result.Length) 'File.Create("report.mhtml", result.Length)

                stream.Write(result, 0, result.Length)
                stream.Close()
            Catch e As Exception
                'MsgBox(e.Message.ToString())
            End Try
            'Catch ex As Exception
            'MsgBox(ex.Message.ToString())
            'End Try
            Return ""
            'BatchErr:
            'Resume Next
    Please provide solution.What are the changes in Reporting service 2008 web service(render method).
    Friday, December 18, 2009 9:36 AM