Trouble invoking webservice that returns pdf in return.
Question:–
- "what should be the return type of webservice when it returns “PDF” file?
- What retrun type does the webservice returns?
- Do I have to to <cfcontent type=“application/pdf”> before webservice consuming code?
- How should I invoke the webservice?
Below is the error and code I am using for this purpose. Can anyone please point out the errors in my code?
Error:-
Cannot perform web service invocation getCreatePDF.
The fault returned when invoking the web service operation is:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException: Content is not allowed in prolog.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.pars... ''
Here is my webservice component.
<cffunction name="getCreatePDF" access="remote" displayname="createPDF" returntype="binary">
<cfsavecontent variable="returnString">
<cfdocument format="PDF">
<cfdocumentitem type="header">National Parks Report</cfdocumentitem>
<!--- Use a footer with current page of totalpages format --->
<cfdocumentitem type="footer">
&nbs p; <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</cfoutput>
</cfdocumentitem>
<h1>Park list</h1>
<table width="95%" border="2" cellspacing="2" cellpadding="2" >
<tr >
&nbs p; <th>Park</th>
&nbs p; <th>Manager</th>
</tr>
</table>
</cfdocument>
</cfsavecontent>
<cfreturn returnString>
</cffunction>
Here is my webservice consuming code:
<cfset objAPI = CreateObject("webservice", "http://localhost:8060/WebServices1.cfc?wsdl")/>
<cfset objAPI._setProperty("Cookie", "myCookie1=hello")>
<cfset objAPI.setMaintainSession(true)>
<cfset objAPI.init()/><br>
<!--- <cfcontent type="application/pdf"> --->
<cfset myResult=objAPI.getCreatePDF()>
<cfset myResult1 = BinaryEncode(myResult,'Base64')>
<cfoutput>
#myResult1#
</cfoutput>