经过一天的努力,搜索互联网和大量的试验和错误,我设法让它工作。
这是成功的代码:
<?php
// maken the functions that we are going to use
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
echo "\n\n";
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
echo "\n\n";
return $d;
}
}
// Fill in the parameters, this will be replaced with results from a form & an initialisation file
$soap_EndPoint = "http://somehost:8080/EngineService/EngineService";
$soap_Wsdl = "${soap_EndPoint}?wsdl";
$p_strDriver = "base64encodedstring";
$p_strFileName = "INPUT";
$p_strFileReturnRegEx = "^.*.(pdf|dlf)$";
$p_strIncludeHeader = "True";
$p_strIncludeMessage = "True";
$p_strPubFile = "InteractiveDocument.pub";
$p_strEngineKey = "removedstring";
// preparing soap client connection
$soap_opts = array (
'location' => $soap_EndPoint ,
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL,
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => TRUE,
'trace' => TRUE,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP);
$soapclient_result = new SoapClient($soap_Wsdl, $soap_opts);
$soap_header = new SoapHeader("urn:hpexstream-services/Engine",'','',FALSE);
$soap_param = array("Compose"=> array("EWSComposeRequest" => array( "driver" => array( "driver" => $p_strDriver, "fileName" => $p_strFileName), "engineOptions" => array( "name" => "KEY", "value" => $p_strEngineKey), "fileReturnRegEx" => $p_strFileReturnRegEx, "includeHeader" => $p_strIncludeHeader, "includeMessageFile" => $p_strIncludeMessage, "pubFile" => $p_strPubFile)));
try {
$result = $soapclient_result->__soapCall("Compose", $soap_param, NULL, $soap_header, $soap_outputHeaders);
/* turn on for debuggin
echo $soapclient_result->__getLastRequest();
echo "\n\n";
echo $soapclient_result->__getLastResponse();
echo "\n\n";
echo $soapclient_result->__getLastResponseHeaders();
echo $soapclient_result->__getTypes();
echo "\n\n";
*/
// the result is set in objects instead of an array
$array = objectToArray($result);
// creating some variables for the files i receive from the soap server
$timeStamp = Time();
$msgFile .= 'hpoutput/'. $timeStamp . '_messageFile.txt';
$dlfFile .= 'hpoutput/'. $timeStamp . '_'. $array["return"]["files"]["fileName"];
// saving the messagefile to the server
$var_str = var_export($array["return"]["engineMessage"], true);
file_put_contents($msgFile, $var_str);
// saving the actual output file to the server
$var_str = serialize($array["return"]["files"]["fileOutput"]);
file_put_contents($dlfFile, $var_str);
} catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
?>