2

嗨,我在编写 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 脚本,做了很多教程,但与我的情况相比,所有这些都很简单。所以我被困住了......

使用此脚本,我确实到达了我的肥皂服务器,但它返回了一个未定义的错误:

$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" ))

?>

我真的希望有人可以帮助我。提前致谢!

亲切的问候, 米诺

4

2 回答 2

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);

}


?>
于 2013-05-03T08:13:04.737 回答
-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>
于 2016-07-10T14:35:12.337 回答