CharlesWCole CharlesWCole - 2 months ago 14
PHP Question

Using Classes Built by wsdl2phpgenerator

I am trying to build and application to make calls to a web service hosted by AAA Cooper Transportation. I know a little about PHP and even less about web services, but I am trying to learn. I was able to make simple web calls to other WSDLs but the AAA Cooper WSDL has many complex types.

AAA Cooper Instructions and WSDL

I ended up using wsdl2phpgenerator to generate the code I need to call the service but now I am stuck. I am not advanced enough to follow the PHP code. Can anyone help me use this code?

I know I need to pass the following, I just don't know how:

$ProNo="73266840";
$ImageType="BL";
$ImageFormat="PDF";
$Token="#######-####-###-######-########";


ActDocumentSearch.php

<?php

include_once('GetDocument.php');
include_once('ActImgSearchServiceRequestVO.php');
include_once('GetDocumentResponse.php');
include_once('ActImgSearchServiceResponseVO.php');
include_once('UserCredentials.php');


/**
*
*/
class ActDocumentSearch extends SoapClient
{

/**
*
* @var array $classmap The defined classes
* @access private
*/
private static $classmap = array(
'GetDocument' => 'GetDocument',
'ActImgSearchServiceRequestVO' => 'ActImgSearchServiceRequestVO',
'GetDocumentResponse' => 'GetDocumentResponse',
'ActImgSearchServiceResponseVO' => 'ActImgSearchServiceResponseVO',
'UserCredentials' => 'UserCredentials');

/**
*
* @param array $config A array of config values
* @param string $wsdl The wsdl file to use
* @access public
*/
public function __construct(array $options = array(), $wsdl = 'http://www.aaacooper.com/ws/ActDocumentSearch.asmx?wsdl')
{
foreach(self::$classmap as $key => $value)
{
if(!isset($options['classmap'][$key]))
{
$options['classmap'][$key] = $value;
}
}

parent::__construct($wsdl, $options);
}

/**
*
* @param GetDocument $parameters
* @access public
*/
public function GetDocument(GetDocument $parameters)
{
return $this->__soapCall('GetDocument', array($parameters));
}

}


<?php

class UserCredentials
{

/**
*
* @var string $token
* @access public
*/
public $token;

/**
*
* @param string $token
* @access public
*/
public function __construct($token)
{
$this->token = $token;
}

}

<?php

class GetDocumentResponse
{

/**
*
* @var ActImgSearchServiceResponseVO $GetDocumentResult
* @access public
*/
public $GetDocumentResult;

/**
*
* @param ActImgSearchServiceResponseVO $GetDocumentResult
* @access public
*/
public function __construct($GetDocumentResult)
{
$this->GetDocumentResult = $GetDocumentResult;
}

}

<?php

class GetDocument
{

/**
*
* @var ActImgSearchServiceRequestVO $actImgSearchServiceRequestVO
* @access public
*/
public $actImgSearchServiceRequestVO;

/**
*
* @param ActImgSearchServiceRequestVO $actImgSearchServiceRequestVO
* @access public
*/
public function __construct($actImgSearchServiceRequestVO)
{
$this->actImgSearchServiceRequestVO = $actImgSearchServiceRequestVO;
}

}
<?php

class ActImgSearchServiceResponseVO
{

/**
*
* @var string $ProNo
* @access public
*/
public $ProNo;

/**
*
* @var string $ImageType
* @access public
*/
public $ImageType;

/**
*
* @var string $ImageFormat
* @access public
*/
public $ImageFormat;

/**
*
* @var anyType $ImageUrl
* @access public
*/
public $ImageUrl;

/**
*
* @var string $ErrorMessage
* @access public
*/
public $ErrorMessage;

/**
*
* @param string $ProNo
* @param string $ImageType
* @param string $ImageFormat
* @param anyType $ImageUrl
* @param string $ErrorMessage
* @access public
*/
public function __construct($ProNo, $ImageType, $ImageFormat, $ImageUrl, $ErrorMessage)
{
$this->ProNo = $ProNo;
$this->ImageType = $ImageType;
$this->ImageFormat = $ImageFormat;
$this->ImageUrl = $ImageUrl;
$this->ErrorMessage = $ErrorMessage;
}

}
<?php

class ActImgSearchServiceRequestVO
{

/**
*
* @var string $ProNo
* @access public
*/
public $ProNo;

/**
*
* @var string $ImageType
* @access public
*/
public $ImageType;

/**
*
* @var string $ImageFormat
* @access public
*/
public $ImageFormat;

/**
*
* @param string $ProNo
* @param string $ImageType
* @param string $ImageFormat
* @access public
*/
public function __construct($ProNo, $ImageType, $ImageFormat)
{
$this->ProNo = $ProNo;
$this->ImageType = $ImageType;
$this->ImageFormat = $ImageFormat;
}

}

Answer

Added this to the main class. I take the PRO and the DOC Type from a form. I then redirect the user to the request image. This is the first example I have seen posted. Not sure if the code is well written but works.

        $ProNo=$_GET['PRO'];
        $ImageType=$_GET['DocType'];
        $ImageFormat="PDF";
        $Token="####################################";

        try{

    $actImage = new ActImgSearchServiceRequestVO($ProNo, $ImageType, $ImageFormat);
    $creds = new UserCredentials($Token);
    $getter = new GetDocument($actImage);
    $searcher = new ActDocumentSearch(array('trace' => 1));

    $header = new SoapHeader('http://www.aaacooper.com/','UserCredentials',$creds);
    $searcher->__setSoapHeaders($header);
    $reciever = $searcher->GetDocument($getter,array($actImage,$creds));  
        }
        catch(SoapFault $exception)
        {
            echo $exception->getMessage();
        }

    if ($reciever->GetDocumentResult->ImageUrl == ''){
    echo '<h1>' . $reciever->GetDocumentResult->ErrorMessage . '</h1>';
    }else{
     header( 'Location: ' . $reciever->GetDocumentResult->ImageUrl ) ;
     }
    ?>
Comments