Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:45:08+00:00 2026-05-24T04:45:08+00:00

Task: To be able to render a PDF when user clicks a link (which

  • 0

Task: To be able to render a PDF when user clicks a link (which is a WCF Service {example: http://localhost:6186/MyReportServices.svc/reports/012}). The Service goes and fetches the report from SSRS Server and returns the Stream. Here is the piece of code that is in .

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class AssistReportServices : IAssistReportServices
{
    public Stream GetReport(int value)
    {
      //skipped some lines of code. 
      try
        {
          result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
          execInfo = rs.GetExecutionInfo();             
        }
      catch (SoapException err)
        {
            throw;
        }
      MemoryStream ms = new MemoryStream();
      ms.Write(result, 0, result.Length);
      ms.Position = 0;
      //WebOperationContext.Current.OutgoingResponse.ContentType = ConfigurationManager.AppSettings["ResponseType"];
      WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
      return ms; 
    }
 }

My Operation Contract looks like:

[OperationContract(Action = "*")]
[WebInvoke(Method = "POST",
    UriTemplate = "reports/{value}")]
Stream GetReport(int value);

So far so good. But here is the problem… When i click the link above, i get the following error in a dialog box with title Adobe Reader and message:

File does not begin with ‘%PDF-‘.

Error Image: https://i.stack.imgur.com/Btiql.png

I can save the Memory Stream to a file and manually open the pdf, and it opens just fine without issues.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:45:09+00:00Added an answer on May 24, 2026 at 4:45 am

    I found where I was going wrong. I had used the Web.Config file to configure my WCF Service. When i switched to a code based configuration using the following code, the service worked and pointed out my errors as well.

    static void Main(string[] args)
    {
    
        ServiceHost serviceHost = new ServiceHost(typeof(MyReportingServices.MyReportServices), ServiceEndpointUri);
        WebHttpBinding binding = new WebHttpBinding();
        ServiceEndpoint sep = serviceHost.AddServiceEndpoint(typeof(MyReportingServices.IMyReportServices), binding, string.Empty);
        sep.Behaviors.Add(new WebHttpBehavior());
        serviceHost.Open();
        Console.WriteLine("Service is running @ " + ServiceEndpointUri);
        Console.WriteLine();
        Console.WriteLine("Press enter to shutdown service.");
        Console.ReadLine();
        serviceHost.Close();
    }
    

    The error was:

    Operation ‘GetReport’ in contract ‘IMyReportServices’ has a path
    variable named ‘value’ which does not have type ‘string’. Variables
    for UriTemplate path segments must have type ‘string’.

    Which I resolved by changing the datatype for my operation parameters to String.

    Thanks to Mrchief, as i used his input to add the following line of code, to help me display a Save/Cancel dialog:-

    WebOperationContext.Current.OutgoingResponse.ContentType = "application/pdf";
    WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-disposition", "inline; filename=apurvReport.pdf"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to change a user's password from a cron task
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>
The task is to take a list of tables which is changeable. Write a
I would like to be able to abort a task that is running from
I am using the asminfo task in NAnt but would like to be able
I need to be able to execute a task for all sub-directories with a
I need to develop a task system that should be able to work on
It's quite frustrating not to be able to do such a simple task: I
Render a WPF control to a bitmap image is not a trivial task as
If I run sudo ant from command line, the ant task is able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.