dExIT dExIT - 11 days ago 8
PHP Question

Using Easy PHP2WSDL generated PHP code

I've scoured all SO,SU and forums regarding talking to complex WSDL through PHP, with no luck, due to lack of knowledge and helpful hand, i almost gave up.

But i found a Open Source service - http://www.stccorp.net/ewsdl2php/wsdl2php.php

And it generated the below code.

<?php

class Authenticate{
var $clientId;//string
var $username;//string
var $password;//string
}
class AuthenticateResponse{
var $AuthenticateResult;//IntegrationResponse
}
class IntegrationResponse{
var $ResponseId;//int
var $TotalCount;//int
var $Detail;//string
var $Statuses;//ArrayOfIntegrationStatusResponse
var $ImportingQueueId;//int
var $SalesOrdersToDespatchIds;//ArrayOfInt
}
class ArrayOfIntegrationStatusResponse{
var $IntegrationStatusResponse;//IntegrationStatusResponse
}
class IntegrationStatusResponse{
var $Reference;//string
var $Status;//IntegrationResponseStatuses
var $LineNo;//int
var $Details;//string
}
class ArrayOfInt{
var $int;//int
}
class GetData{
var $getRequest;//GetRequest
}
class GetRequest{
var $TemplateName;//string
var $PageNo;//int
var $ItemsPerPage;//int
var $SearchClause;//string
}
class GetDataResponse{
var $GetDataResult;//IntegrationResponse
}
class UserSessionCredentials{
var $UserId;//int
var $ClientId;//string
var $SessionId;//string
}
class GetSystemSettings{
}
class GetSystemSettingsResponse{
var $GetSystemSettingsResult;//IntegrationResponse
}
class GetReportData{
var $getReportRequest;//GetReportRequest
}
class GetReportRequest{
var $FilterClause;//string
var $OrderBy;//string
var $Columns;//string
}
class GetReportDataResponse{
var $GetReportDataResult;//IntegrationResponse
}
class GetReportColumns{
var $templateName;//string
}
class GetReportColumnsResponse{
var $GetReportColumnsResult;//IntegrationResponse
}
class GetSaveTemplate{
var $templateName;//string
}
class GetSaveTemplateResponse{
var $GetSaveTemplateResult;//IntegrationResponse
}
class SaveData{
var $saveRequest;//SaveRequest
}
class SaveRequest{
var $TemplateName;//string
var $CsvData;//string
var $Action;//int
}
class SaveDataResponse{
var $SaveDataResult;//IntegrationResponse
}
class SubscribeEvent{
var $eventType;//SubscriptionEventTypes
var $filter;//string
var $callbackUrl;//string
}
class SubscribeEventResponse{
var $SubscribeEventResult;//IntegrationResponse
}
class SubscribeEventWithSitesFilters{
var $eventType;//SubscriptionEventTypes
var $filter;//string
var $sitesFilter;//string
var $callbackUrl;//string
}
class SubscribeEventWithSitesFiltersResponse{
var $SubscribeEventWithSitesFiltersResult;//IntegrationResponse
}
class SubscribePostEvent{
var $eventType;//SubscriptionEventTypes
var $filter;//string
var $postUrl;//string
var $postParams;//string
}
class SubscribePostEventResponse{
var $SubscribePostEventResult;//IntegrationResponse
}
class UnsubscribeEvent{
var $subscriptionId;//int
}
class UnsubscribeEventResponse{
var $UnsubscribeEventResult;//IntegrationResponse
}
class Range
{
var $soapClient;

private static $classmap = array('Authenticate'=>'Authenticate'
,'AuthenticateResponse'=>'AuthenticateResponse'
,'IntegrationResponse'=>'IntegrationResponse'
,'ArrayOfIntegrationStatusResponse'=>'ArrayOfIntegrationStatusResponse'
,'IntegrationStatusResponse'=>'IntegrationStatusResponse'
,'ArrayOfInt'=>'ArrayOfInt'
,'GetData'=>'GetData'
,'GetRequest'=>'GetRequest'
,'GetDataResponse'=>'GetDataResponse'
,'UserSessionCredentials'=>'UserSessionCredentials'
,'GetSystemSettings'=>'GetSystemSettings'
,'GetSystemSettingsResponse'=>'GetSystemSettingsResponse'
,'GetReportData'=>'GetReportData'
,'GetReportRequest'=>'GetReportRequest'
,'GetReportDataResponse'=>'GetReportDataResponse'
,'GetReportColumns'=>'GetReportColumns'
,'GetReportColumnsResponse'=>'GetReportColumnsResponse'
,'GetSaveTemplate'=>'GetSaveTemplate'
,'GetSaveTemplateResponse'=>'GetSaveTemplateResponse'
,'SaveData'=>'SaveData'
,'SaveRequest'=>'SaveRequest'
,'SaveDataResponse'=>'SaveDataResponse'
,'SubscribeEvent'=>'SubscribeEvent'
,'SubscribeEventResponse'=>'SubscribeEventResponse'
,'SubscribeEventWithSitesFilters'=>'SubscribeEventWithSitesFilters'
,'SubscribeEventWithSitesFiltersResponse'=>'SubscribeEventWithSitesFiltersResponse'
,'SubscribePostEvent'=>'SubscribePostEvent'
,'SubscribePostEventResponse'=>'SubscribePostEventResponse'
,'UnsubscribeEvent'=>'UnsubscribeEvent'
,'UnsubscribeEventResponse'=>'UnsubscribeEventResponse'

);

function __construct($url='integrationservicev4.asmx?WSDL')
{
$this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
}

function Authenticate(Authenticate $Authenticate)
{

$AuthenticateResponse = $this->soapClient->Authenticate($Authenticate);
return $AuthenticateResponse;

}
function GetData(GetData $GetData)
{

$GetDataResponse = $this->soapClient->GetData($GetData);
return $GetDataResponse;

}
function GetSystemSettings(GetSystemSettings $GetSystemSettings)
{

$GetSystemSettingsResponse = $this->soapClient->GetSystemSettings($GetSystemSettings);
return $GetSystemSettingsResponse;

}
function GetReportData(GetReportData $GetReportData)
{

$GetReportDataResponse = $this->soapClient->GetReportData($GetReportData);
return $GetReportDataResponse;

}
function GetReportColumns(GetReportColumns $GetReportColumns)
{

$GetReportColumnsResponse = $this->soapClient->GetReportColumns($GetReportColumns);
return $GetReportColumnsResponse;

}
function GetSaveTemplate(GetSaveTemplate $GetSaveTemplate)
{

$GetSaveTemplateResponse = $this->soapClient->GetSaveTemplate($GetSaveTemplate);
return $GetSaveTemplateResponse;

}
function SaveData(SaveData $SaveData)
{

$SaveDataResponse = $this->soapClient->SaveData($SaveData);
return $SaveDataResponse;

}
function SubscribeEvent(SubscribeEvent $SubscribeEvent)
{

$SubscribeEventResponse = $this->soapClient->SubscribeEvent($SubscribeEvent);
return $SubscribeEventResponse;

}
function SubscribeEventWithSitesFilters(SubscribeEventWithSitesFilters $SubscribeEventWithSitesFilters)
{

$SubscribeEventWithSitesFiltersResponse = $this->soapClient->SubscribeEventWithSitesFilters($SubscribeEventWithSitesFilters);
return $SubscribeEventWithSitesFiltersResponse;

}
function SubscribePostEvent(SubscribePostEvent $SubscribePostEvent)
{

$SubscribePostEventResponse = $this->soapClient->SubscribePostEvent($SubscribePostEvent);
return $SubscribePostEventResponse;

}
function UnsubscribeEvent(UnsubscribeEvent $UnsubscribeEvent)
{

$UnsubscribeEventResponse = $this->soapClient->UnsubscribeEvent($UnsubscribeEvent);
return $UnsubscribeEventResponse;

}
function Authenticate(Authenticate $Authenticate)
{

$AuthenticateResponse = $this->soapClient->Authenticate($Authenticate);
return $AuthenticateResponse;

}
function GetData(GetData $GetData)
{

$GetDataResponse = $this->soapClient->GetData($GetData);
return $GetDataResponse;

}
function GetSystemSettings(GetSystemSettings $GetSystemSettings)
{

$GetSystemSettingsResponse = $this->soapClient->GetSystemSettings($GetSystemSettings);
return $GetSystemSettingsResponse;

}
function GetReportData(GetReportData $GetReportData)
{

$GetReportDataResponse = $this->soapClient->GetReportData($GetReportData);
return $GetReportDataResponse;

}
function GetReportColumns(GetReportColumns $GetReportColumns)
{

$GetReportColumnsResponse = $this->soapClient->GetReportColumns($GetReportColumns);
return $GetReportColumnsResponse;

}
function GetSaveTemplate(GetSaveTemplate $GetSaveTemplate)
{

$GetSaveTemplateResponse = $this->soapClient->GetSaveTemplate($GetSaveTemplate);
return $GetSaveTemplateResponse;

}
function SaveData(SaveData $SaveData)
{

$SaveDataResponse = $this->soapClient->SaveData($SaveData);
return $SaveDataResponse;

}
function SubscribeEvent(SubscribeEvent $SubscribeEvent)
{

$SubscribeEventResponse = $this->soapClient->SubscribeEvent($SubscribeEvent);
return $SubscribeEventResponse;

}
function SubscribeEventWithSitesFilters(SubscribeEventWithSitesFilters $SubscribeEventWithSitesFilters)
{

$SubscribeEventWithSitesFiltersResponse = $this->soapClient->SubscribeEventWithSitesFilters($SubscribeEventWithSitesFilters);
return $SubscribeEventWithSitesFiltersResponse;

}
function SubscribePostEvent(SubscribePostEvent $SubscribePostEvent)
{

$SubscribePostEventResponse = $this->soapClient->SubscribePostEvent($SubscribePostEvent);
return $SubscribePostEventResponse;

}
function UnsubscribeEvent(UnsubscribeEvent $UnsubscribeEvent)
{

$UnsubscribeEventResponse = $this->soapClient->UnsubscribeEvent($UnsubscribeEvent);
return $UnsubscribeEventResponse;

}}


?>


I would like to ask, if someone could point out how can i use it?
I Would realy appreciate any help to create a request that has :



SOAP Headers:

UserSessionCredentials.UserId[0]:

UserSessionCredentials.ClientId[0]:

UserSessionCredentials.SessionId[0]:

SOAP BODY

GetReportData.getReportRequest[0].TemplateName[0]:

GetReportData.getReportRequest[0].PageNo[0]:

GetReportData.getReportRequest[0].ItemsPerPage[0]:

GetReportData.getReportRequest[0].SearchClause[0]:

GetReportData.getReportRequest[0].FilterClause[0]:

GetReportData.getReportRequest[0].OrderBy[0]:
GetReportData.getReportRequest[0].Columns[0]:


SOLUTION was made from the below answer and StackOverflow question:Set SoapHeaders with multiple namespace in PHP all clients who will need this:

<?php
$ns = "http://www.thenamespace.net/";
$userid = 123; // you can find out this part from loggin into WMS and checking HTTP requests/responses and you can get the ID
$clientid = "aaa1234";
$username = "username";
$password = base64_encode("password");
$socket_context = stream_context_create(array('http' => array('protocol_version' => 1.0)));
$client = new SoapClient("http://wms.system.net/$clientid/resources/integrationservicev4.asmx?WSDL", array('exceptions' => 0,'stream_context' => $socket_context,'trace' => 1));


// body vars
$someTemplateName = 'Critical'; //from the created reporting template
$somePageNo = 1;
$someItemsPerPage = 1000;
$someSearchClause = '';
$someFilterClause = 'RequestedDeliveryDate >= DateTime(2017,04,13,06,00,00)'; // here we can do $date = date(Y,m,d,) . $time
$someOrderBy = '[Type]';
$someColumns = '[Type],[Total]'; // columns to show

$params = array("clientId"=>$clientid,"username"=>$username,"password"=>$password);
$start = $client->Authenticate($params);
if (is_soap_fault($start)) {
trigger_error("SOAP Fault: (faultcode: {$start->faultcode}, faultstring: {$start->faultstring})", E_USER_ERROR);
print "<br />";
} else {
$response = $start->AuthenticateResult->Detail;
$response_explode = explode(",",$response);
$sessionid = $response_explode[1];


//Body of the Soap Header.
$headerbody = array('UserId' => $userid,'ClientId' => $clientid, 'SessionId' => $sessionid);
//Create Soap Header.
$header = new SOAPHeader($ns, 'UserSessionCredentials', $headerbody);
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);

$body = array( 'TemplateName'=>$someTemplateName,
'PageNo'=>$somePageNo,
'ItemsPerPage'=>$someItemsPerPage,
'SearchClause'=>$someSearchClause,
'FilterClause'=>$someFilterClause,
'OrderBy'=>$someOrderBy,
'Columns'=>$someColumns);

}
$params = array('getReportRequest' => $body);
$reply = $client->GetReportData($params); // ACTUAL MAGIC
var_dump($reply);
print_r($start);
echo "<br><br><br>ResponseT:\n" . $client->__getLastResponse() . "\n";
echo "<br><br><br>REQUEST:\n" . $client->__getLastRequest() . "\n";
?>

Answer

Based only on the SOAP Headers and BODY you said on your second part, I can answer the following:

You can set your request like this:

//Body of the Soap Header.
$headerbody = array('UserId' => $someUserId,
                    'ClientId' => $someClientId,
                    'SessionId' => $someSessionId);

$ns = 'http://namespace.example.com/'; //Namespace of the WS.

//Create Soap Header.       
$header = new SOAPHeader($ns, 'RequestorCredentials', $headerbody);       

//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header); 

//Soap Body
$body = array(  'TemplateName'=>$someTemplateName,
                'PageNo'=>$somePageNo,
                'ItemsPerPage'=>$someItemsPerPage,
                'SearchClause'=>$someSearchClause,
                'FilterClause'=>$someFilterClause,
                'OrderBy'=>$someOrderBy,
                'Columns'=>$someColumns);
$reply = $soap_client->call('yourfunction', array('parameters' => $body));

Check information about the headers here and about the body here

However if I check the PHP2WSDL code you pasted, I notice that class GetReportData only has fields $FilterClause, $OrderBy, $Columns

whereas fields $TemplateName, $PageNo, $ItemsPerPage and $SearchClause belong to class GetRequest which is not included in your question. Based on the things you need to use, you should only use the following code from the PHP2WSDL output

<?php
class UserSessionCredentials{
    var $UserId;//int
    var $ClientId;//string
    var $SessionId;//string
}
class GetReportData{
    var $getReportRequest;//GetReportRequest
}
class GetReportRequest{
    var $FilterClause;//string
    var $OrderBy;//string
    var $Columns;//string
}
class GetReportDataResponse{
    var $GetReportDataResult;//IntegrationResponse
}

class Range  {
 var $soapClient;

    private static $classmap = array('Authenticate'=>'Authenticate'
    ,'AuthenticateResponse'=>'AuthenticateResponse'
    ,'IntegrationResponse'=>'IntegrationResponse'
    ,'ArrayOfIntegrationStatusResponse'=>'ArrayOfIntegrationStatusResponse'
    ,'IntegrationStatusResponse'=>'IntegrationStatusResponse'
    ,'ArrayOfInt'=>'ArrayOfInt'
    ,'GetData'=>'GetData'
    ,'GetRequest'=>'GetRequest'
    ,'GetDataResponse'=>'GetDataResponse'
    ,'UserSessionCredentials'=>'UserSessionCredentials'
    ,'GetSystemSettings'=>'GetSystemSettings'
    ,'GetSystemSettingsResponse'=>'GetSystemSettingsResponse'
    ,'GetReportData'=>'GetReportData'
    ,'GetReportRequest'=>'GetReportRequest'
    ,'GetReportDataResponse'=>'GetReportDataResponse'
    ,'GetReportColumns'=>'GetReportColumns'
    ,'GetReportColumnsResponse'=>'GetReportColumnsResponse'
    ,'GetSaveTemplate'=>'GetSaveTemplate'
    ,'GetSaveTemplateResponse'=>'GetSaveTemplateResponse'
    ,'SaveData'=>'SaveData'
    ,'SaveRequest'=>'SaveRequest'
    ,'SaveDataResponse'=>'SaveDataResponse'
    ,'SubscribeEvent'=>'SubscribeEvent'
    ,'SubscribeEventResponse'=>'SubscribeEventResponse'
    ,'SubscribeEventWithSitesFilters'=>'SubscribeEventWithSitesFilters'
    ,'SubscribeEventWithSitesFiltersResponse'=>'SubscribeEventWithSitesFiltersResponse'
    ,'SubscribePostEvent'=>'SubscribePostEvent'
    ,'SubscribePostEventResponse'=>'SubscribePostEventResponse'
    ,'UnsubscribeEvent'=>'UnsubscribeEvent'
    ,'UnsubscribeEventResponse'=>'UnsubscribeEventResponse'

    );

     function __construct($url='integrationservicev4.asmx?WSDL')
     {
      $this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
     }


    function GetReportData(GetReportData $GetReportData)
    {

    $GetReportDataResponse = $this->soapClient->GetReportData($GetReportData);
    return $GetReportDataResponse;

    }
}
?>          

Lastly, I don't see any wsdl on the url integrationservicev4.asmx?WSDL so in case you haven't changed it yourself, be careful as the service may not reply to you, even if you implement your client correctly