Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

i have a webservice in C# which return a pdf file. i have another application in PHP which will call this webservice and allow users to download this pdf.

my C# code is

C#
[WebMethod]
public byte[] GetFile()
{
      string fileName = @"D:\pdf\5.pdf";
      byte[] filebytes = null;
            using (FileStream fs = File.OpenRead(fileName))
            {
                filebytes = new byte[fs.Length];
                fs.Read(filebytes, (int)0, (int)fs.Length);
            }

      return filebytes;
}


Here is the php code which i am using to consume

PHP
<?php

$client = new SoapClient("http://localhost:63547/Service1.asmx?WSDL");
$result = $client->GetSimple();
print_r($result);
?>


But it returns some thing like following

stdClass Object ( [GetSimpleResult] => %PDF-1.6 %crackpdf.com 1 0


Please help how can i consume it in php :)
Posted
Updated 25-Apr-11 23:59pm
v3
Comments
Sandeep Mewara 23-Apr-11 1:38am    
Wouldn't calling this methog directly do?
Fawad Ahsan 25-Apr-11 7:19am    
Nops :(

1 solution

%PDF indicates the content of the pdf file because this is the start of the pdf header. You probably need to tell the client that pdf content is coming and not text.

Try something like this:
header('Content-Type: application/pdf');
echo $result;
?>


Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900