Jump to content
php.lv forumi

Runat ar WSDL servisu caur PHP SOAP client


dExIT

Recommended Posts

Sveiki,
Velejos vispirms atvainoties par garumzimju neessamiibu, valsts kura atrodos un vieta no kuras rakstu ierobezo mani.

Problema ar ko saskaros:
* ir WSDL serviss no kura velos pieprasit datus par reportiem
* Ir manualis ka ar vinju runat tikai caur C# un vienkarshi XML/SOAP envelope request/response piemeeri
* Ir stradajosh kods no StackOverflow -> Apskatam te lai gjenereetu valid Auth un ieguutu vajadziigo "SESSION ID".

Pec SO koda es pievienoju vienkarshu pieprasijumu
 

$client->GetSystemSettings(); 

Kas gjeneree:
 

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <UserSessionCredentials xmlns="http://www.NSadrese.net/">
      <UserId>int</UserId>
      <ClientId>string</ClientId>
      <SessionId>string</SessionId>
    </UserSessionCredentials>
  </soap:Header>
  <soap:Body>
    <GetSystemSettings xmlns="http://www.NSadrese.net/" />
  </soap:Body>
</soap:Envelope>

Atbilde

<IntegrationResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.NSadrese.net/">
<ResponseId>0</ResponseId>
<TotalCount>0</TotalCount>
<Detail>dd/MM/yyyy HH:mm</Detail>
<Statuses/>
<ImportingQueueId>0</ImportingQueueId>
<SalesOrdersToDespatchIds/>
</IntegrationResponse>

Kas pieraada ka es speeju sarunaaties ar sho WSDL servisu.
Bet tiklidz es veelos piekljuut savadaakiem datiem, man vienmeer raada ka ir objekts kursh nav "atrakstiits", lasot dziljaak saprotu ka neesmu pareizi izveidojis pieprasiijumu (struktruura).
Vel paseedeeju paaris dienas un sapratu ka nav lemts.

Tad uzduros uz shi servisa http://www.soapclient.com/soaptest.html
Kas ljauj man ievadit WSDL linku, un gjeneree HTML INPUT formas un te viss straadaa, es veeleetos sho informaaciju padot no sava WEBservera caur PHP SOAP bet dotajaa gadijumaa es laizhu visu caur file_get_contents kaa ENCODED url request uz sho formu un tad sijaaju XML responsi etc.
Ludzu skatiet :
Piemers2.jpg.6368ffcd77cb14af5fc2805293e232a7.jpg

Gribetu zinat ka shis Serviss uzgjeneree pareizus pieprasijumus
Un vel vairaak neizprotu kadelj kad pieprasijums ir pabeigts, XML rezultats ir shads:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetReportDataResponse xmlns="http://www.NSadrese.net/">
<GetReportDataResult>
<ResponseId>0</ResponseId>
<TotalCount>1896</TotalCount>
<Detail>
"Total","Type" "1747","Allocated" "14","Partially allocated" "1","Partially despatched" "8","Partially picked" "126","Picked"
</Detail>
<Statuses/>
<ImportingQueueId>0</ImportingQueueId>
<SalesOrdersToDespatchIds/>
</GetReportDataResult>
</GetReportDataResponse>
</soap:Body>
</soap:Envelope>

PS>Mani pa lielam interesee tikai <TotalCount> un <Detail>
Pashaas beigaas sapratu ka esmu lops un vajadzeetu saprast ka lietot CLASS / un CLASSMAP, bet

Tad izmantojot http://www.stccorp.net/ewsdl2php/wsdl2php.php

Ieguvu sho :

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

}}


?>                                
                            


-- Vai kaads butu spejigs mani apgaismot ka izmantot/lietot sho gjenereeto PHP failu lai iegutu sev velamos rezultatus -> GetReportData ?
Atvainojos varbut par nelogjiskumu/valodu esmu gandriz jau zaudejis praatu un nespeeju atrast resursus kas man speetu palidzeet.

-- EDIT---

Ja kaads veelas atbildeet uz sho jautaajumu SO - luudzu : http://stackoverflow.com/questions/43340131/using-easy-php2wsdl-generated-php-code

Edited by dExIT
Pievienoju StackOverflow linku
Link to comment
Share on other sites

Ja tu zini pareizo SOAP request struktūru, tad uzrakstīt atbilstošu PHP SoapClient requestu nevajadzētu būt problēmām.

Iedod kaut vienu nestrādājoša pieprasījuma request struktūru.

Principā request body tev jau vajadzētu saprast, kā veidot, vnk $soap->SomeFunction(['foo' => 'bar']), bet request headerus tev @ SO tas čalis aprakstīja:

$headerValues = [
    'UserId'    => $someUserId,
    'ClientId'  => $someClientId,
    'SessionId' => $someSessionId
];

$ns = 'http://namespace.example.com/'; // šo ņem no <UserSessionCredentials xmlns="http://www.NSadrese.net/">
$header = new SOAPHeader($ns, 'UserSessionCredentials', $headerValues);
$soap->__setSoapHeaders($header);

Teorētiski ar to vajadzētu pietikt, tālāk izsauc `$soap->GetSystemSettings()` un vajadzētu aiziet.

 

P.S. Viņš tāpat paņēma copy-paste no šejienes: http://php.net/manual/en/soapclient.setsoapheaders.php#93460

Edited by jurchiks
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...