您好,我没有很多编程Web服务客户端的经验。在过去(在常见的Web服务之前)我使用php工作,所以我要回到自己的根源。
使用soapui我创建了以下(工作)请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eng="urn:hpexstream-services/Engine">
<soapenv:Header/>
<soapenv:Body>
<eng:Compose>
<EWSComposeRequest>
<driver>
<driver>base64encodedstring</driver>
<fileName>INPUT</fileName>
</driver>
<engineOptions>
<name>KEY</name> <value>string</value>
</engineOptions>
<fileReturnRegEx>^.*.(pdf|dlf)$</fileReturnRegEx>
<includeHeader>True</includeHeader>
<includeMessageFile>True</includeMessageFile>
<pubFile>InteractiveDocument.pub</pubFile>
</EWSComposeRequest>
</eng:Compose>
</soapenv:Body>
</soapenv:Envelope>
在我的项目的第一阶段,我想在php中创建一个soapclient来创建soaprequest,如上所示。如果这有效,我想用提供变量的表单扩展这个项目。
我已经尝试了几个PHP脚本,做了很多tuturials但是所有这些都比我的情况简单。所以我被卡住了......
使用这个脚本我会到达我的soapserver,但它会返回一个未定义的错误:
$client = new SoapClient("http://localhost:8080/EngineService/EngineService?wsdl");
$answer = $client->Compose("EWSComposeRequest", array('driver' => "base64encodedstring",'fileName' => "INPUT",'fileReturnRegEx' => "^.*.(pdf|dlf)$",'includeHeader' => "True","includeMessageFile" => "True","pubFile" => "InteractiveDocument.pub" ))
&GT;
我真的希望有人可以帮助我。 提前谢谢!
亲切的问候, MIJNO
答案 0 :(得分:1)
经过一天的努力,搜索互联网和大量的反复试验,我设法让它发挥作用。
以下是执行该技巧的代码:
<?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);
}
?>
答案 1 :(得分:-1)
如何在java中创建高级soap请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eng="urn:hpexstream-services/Engine">
<soapenv:Header/>
<soapenv:Body>
<eng:Compose>
<EWSComposeRequest>
<driver>
<driver>PGN1c3RvbWVyPg0KICAgPGZpcnN0TmFtZT5NZXJpZW08L2ZpcnN0TmFtZT4NCiAgICAgIDxsYXN0TmFtZT5CZWxtb2todGFyPC9sYXN0TmFtZT4NCiAgIA0KPC9jdXN0b21lcj4NCjxjdXN0b21lcj4NCiAgIDxmaXJzdE5hbWU+QWhtZWQ8L2ZpcnN0TmFtZT4NCiAgICAgIDxsYXN0TmFtZT5CZW91bWFpejwvbGFzdE5hbWU+DQogICANCjwvY3VzdG9tZXI+DQo8Y3VzdG9tZXI+DQogICA8Zmlyc3ROYW1lPkhhbXphPC9maXJzdE5hbWU+DQogICAgICA8bGFzdE5hbWU+QmVua2hhbGVkPC9sYXN0TmFtZT4NCiAgIA0KPC9jdXN0b21lcj4=</driver>
<fileName>INPUT</fileName>
</driver>
<driverEncoding>UTF-8</driverEncoding>
<engineOptions>
<name>RUNMODE</name>
<value>PRODUCTION</value>
</engineOptions>
<fileReturnRegEx>?</fileReturnRegEx>
<includeHeader>?</includeHeader>
<includeMessageFile>?</includeMessageFile>
<outputFile>
<directory>out</directory>
<fileName>sortie</fileName>
</outputFile>
<pubFile>PackageTest.pub</pubFile>
</EWSComposeRequest>
</eng:Compose>
</soapenv:Body>
</soapenv:Envelope>