PHP SOAP Client Values and Attributes Not Loading - php

I am trying to make a SOAP call using PHP5. Here is the working schema:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cat="http://com.xxx.xxxx/management/catalog">
<soapenv:Header/>
<soapenv:Body>
<cat:ManageCustomProducts siteId="0">
<!--You have a CHOICE of the next 2 items at this level-->
<!--0 to 25 repetitions:-->
<cat:task id="?">
<cat:insertCustomProduct manufacturerId="?" manufacturerPartNo="?" categoryId="?" categoryType="default">
<cat:skus>
<!--Zero or more repetitions:-->
<cat:sku type="?" number="?"/>
</cat:skus>
<cat:resources>
<!--Zero or more repetitions:-->
<cat:resource type="?" status="?" url="?"/>
</cat:resources>
<cat:locales>
<!--1 or more repetitions:-->
<cat:locale language="?" country="?">
<cat:descriptions>
<!--Zero or more repetitions:-->
<cat:description type="?">e gero</cat:description>
</cat:descriptions>
<cat:marketingDescription>cum sonoras</cat:marketingDescription>
</cat:locale>
</cat:locales>
</cat:insertCustomProduct>
</cat:task>
</cat:ManageCustomProducts>
Here is my code to generate the SOAP XML...
$params=array(array(
'siteId' => '0',
'task' => array('id' => '1',
'insertCustomProduct' => array('manufacturerId' => '10000', 'manufacturerPartNo' => 'abc123', 'categoryId' => '20000', 'categoryType' => 'default',
'skus' => array('sku' => array('type' => 'MANUFACTURPARTNO', 'number' => 'abc123')),
'resources' => array('resource' => array('type' => '500', 'status' => 'Published', 'url' => 'http://content.xxx.com/img.jpg')),
'locales' => array('locale' => array('language' => 'en', 'country' => 'US',
'descriptions' => array('description' => array('_' =>'egeros', 'type' => '1')),
'marketingDescription' => array('_' => 'cum sonoras')
)
)
)
)
)
);
$result = $client->__soapCall("ManageCustomProducts",$params);
Here is the result...
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com.xxx.xxx/management/catalog">
<SOAP-ENV:Body>
<ns1:ManageCustomProducts siteId="0">
<ns1:task id="1">
<ns1:insertCustomProduct manufacturerId="10000" manufacturerPartNo="abc123" categoryId="20000" categoryType="default">
<ns1:skus>
<ns1:sku type="MANUFACTURPARTNO" number="abc123"/>
</ns1:skus>
<ns1:resources>
<ns1:resource type="500" status="Published" url="http://content.xxx.com/img.jpg"/>
</ns1:resources>
<ns1:locales>
<ns1:locale language="en" country="US">
<ns1:descriptions>
<ns1:description type="1"/>
</ns1:descriptions>
<ns1:marketingDescription/>
</ns1:locale>
</ns1:locales>
</ns1:insertCustomProduct>
</ns1:task>
</ns1:ManageCustomProducts>
Even though I am using the suggested format of:
https://stackoverflow.com/a/1419407/3280665
array("foo" => array("_" => "cheese", "bar"=>"moo"));
This should produce following XML
<foo bar="moo">cheese</foo>`
It is not adding the element value for description or marketingDescription. What am I doing wrong?
Thanks!
Update: I can now add the nodes, but how do I add the Type attribute to the description node?
$desc=array();
$desc[]=new SoapVar("This is description 1",XSD_STRING,null,null,'ns1:description');
$desc[]=new SoapVar("This is description 2",XSD_STRING,null,null,'ns1:description');
$description = new SoapVar($desc, SOAP_ENC_OBJECT, null,null,'description');'

Related

SOAP call PHP not sending all parameters

I am trying to make a SOAP call in PHP while I am trying to pass some parameters some of them are never sent. I do not really know if it is a problem about building the LoginYInsertarEvento2Params object or it is more related about the soap call.
This is the object that I build for making the call
$LoginYInsertarEvento2Params = array(
"SystemUser" => "XXXXX",
"Password" => "XXXXXX",
"Dominio" => $registration,
"NroSerie" => $terminal_serial,
"Codigo" => "",
"Latitud" => $latitude,
"Longitud" => $longitude,
"Altitud" => "0",
"Velocidad" => $speed,
"FechaHoraEvento" => date('c', strtotime($fecha_evento)),
"FechaHoraRecepcion" => date('c', strtotime($fecha_registro)),
"Valido" => true,
"Sensores" =>array ( ["Temperatura" => $temp], ["Luminosidad" => $lum] )
);
This the request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="XXXXXXXXXXXXXXXXXXX">
<SOAP-ENV:Body>
<ns1:LoginYInsertarEvento2>
<ns1:SystemUser>XXXXX</ns1:SystemUser>
<ns1:Password>XXXXX</ns1:Password>
<ns1:Dominio>XXXXXX</ns1:Dominio>
<ns1:NroSerie>-1</ns1:NroSerie>
<ns1:Codigo></ns1:Codigo>
<ns1:Latitud>40.348054</ns1:Latitud>
<ns1:Longitud>-3.681576</ns1:Longitud>
<ns1:Altitud>0</ns1:Altitud>
<ns1:Velocidad>0</ns1:Velocidad>
<ns1:FechaHoraEvento>2020-10-09T12:50:40+02:00</ns1:FechaHoraEvento>
<ns1:FechaHoraRecepcion>2020-10-09T12:50:56+02:00</ns1:FechaHoraRecepcion>
<ns1:Valido>true</ns1:Valido>
<ns1:Sensores>
<ns1:pSensor/>
<ns1:pSensor/>
</ns1:Sensores>
</ns1:LoginYInsertarEvento2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And it should be like this one...
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<LoginYInsertarEvento2 xmlns="http://unisolutions.com.ar/">
<SystemUser>XXXXXX</SystemUser>
<Password>xxxxxxxx</Password>
<Dominio>XXXXXXX</Dominio>
<NroSerie>-1</NroSerie>
<Codigo />
<Latitud>41.748311</Latitud>
<Longitud>-0.848768</Longitud>
<Altitud>274</Altitud>
<Velocidad>0</Velocidad>
<FechaHoraEvento>2020-10-06T09:36:56</FechaHoraEvento>
<FechaHoraRecepcion>2020-10-06T09:36:56</FechaHoraRecepcion>
<Valido>true</Valido>
<Sensores>
<pSensor>
<Clave>Temperatura</Clave>
<Valor>11.6</Valor>
</pSensor>
<pSensor>
<Clave>Luminosidad</Clave>
<Valor>0</Valor>
</pSensor>
</Sensores>
</LoginYInsertarEvento2>
</s:Body>
</s:Envelope>
Thanks guys!
Judging by what you expect your output to be. Try changing the structure to look like this:
$LoginYInsertarEvento2Params = array(
"SystemUser" => "XXXXX",
"Password" => "XXXXXX",
"Dominio" => $registration,
"NroSerie" => $terminal_serial,
"Codigo" => "",
"Latitud" => $latitude,
"Longitud" => $longitude,
"Altitud" => "0",
"Velocidad" => $speed,
"FechaHoraEvento" => date('c', strtotime($fecha_evento)),
"FechaHoraRecepcion" => date('c', strtotime($fecha_registro)),
"Valido" => true,
"Sensores" =>array (
["Clave" => "Temperatura", "Valor" => $temp],
["Clave" => "Luminosidad", "Valor" => $lum]
)
);
I may be wrong, but it just looks like the Sensores structure is incorrect.

Passing xml value as array to soap client PHP

I have xml data to passing to SOAPClient as array
this is my xml data that I want to pass to SOAPClient
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cb5="http://tes.com" xmlns:smar="http://tes.com/Search">
<soapenv:Header />
<soapenv:Body>
<cb5:SmartSearchIndividual>
<cb5:query>
<smar:InquiryReason>Reason</smar:InquiryReason>
<smar:InquiryReasonText />
<smar:Parameters>
<smar:DateOfBirth>1985-05-01</smar:DateOfBirth>
<smar:FullName>J Doe</smar:FullName>
<smar:IdNumbers>
<smar:IdNumberPairIndividual>
<smar:IdNumber>123456789</smar:IdNumber>
<smar:IdNumberType>KTP</smar:IdNumberType>
</smar:IdNumberPairIndividual>
</smar:IdNumbers>
</smar:Parameters>
</cb5:query>
</cb5:SmartSearchIndividual>
</soapenv:Body>
</soapenv:Envelope>
I passing this xml to array like this
$params = array(
'InquiryReason' => 'Reason',
'InquiryReasonText' => '',
'Parameters' => array(
'DateOfBirth' => '1985-05-01',
'FullName' => 'J Doe',
'IdNumbers' => array(
'IdNumberPairIndividual' => array(
'IdNumber' => '123456789',
'IdNumberType' => 'KTP'
)
)
)
);
$response = $client->SmartSearchIndividual($params);
when I submit this show an error The formatter threw an exception while trying to deserialize ....
please help.
thanks!

I want to send a soap request using php with multiple items

i want to send a soap request using php but i found a problem here is what i have to send as XML format.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:getImpayee>
<tem:tocken>reererer</tem:tocken>
<tem:CodeCreancier>1013</tem:CodeCreancier>
<tem:CodeCreance>01</tem:CodeCreance>
<tem:crVals>
<tem:CreancierVals>
<tem:nomChamp>montant</tem:nomChamp>
<tem:ValeurChamp>45</tem:ValeurChamp>
</tem:CreancierVals>
<tem:CreancierVals>
<tem:nomChamp>ND</tem:nomChamp>
<tem:ValeurChamp>0663143327</tem:ValeurChamp>
</tem:CreancierVals>
</tem:crVals>
</tem:getImpayee>
</soap:Body>
</soap:Envelope>
but the problem is that there is multiple "tem:CreancierVals" when i use this
$client->__setLocation(url_PaiementWS);
$result = $client->getImpayee(
array(
'tocken' => $_SESSION['tocken'],
'CodeCreancier' => $CodeCreancier,
'CodeCreance' => $CodeCreance,
'crVals' => array (
'CreancierVals' => array(
'nomChamp' => 'montant',
'ValeurChamp' => $montant
),
'CreancierVals' => array(
'nomChamp' => 'ND',
'ValeurChamp' => $ND
)
)
)
);
it doesnt work
its like reseting the "CreancierVals" val
is there a solution in which i can send pure xml using php ? or just a dynamic method that doesn't reseting the "CreancierVals" val but add one to the other as an array for example. thanks
Try this:
$result = $client->getImpayee(
[
'tocken' => $_SESSION['tocken'],
'CodeCreancier' => $CodeCreancier,
'CodeCreance' => $CodeCreance,
'crVals' => [
'CreancierVals' => [
[
'nomChamp' => 'montant',
'ValeurChamp' => $montant,
],
[
'nomChamp' => 'ND',
'ValeurChamp' => $ND,
],
],
],
]
);

PHP not modifying header info

I am logging into a server with soap and retreiving a token, no problem....
I then add the token to the soap:header.
This is what I am trying create.
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<WSAuthorization xmlns="http://url.com/testing/">
<Token>string</Token>
</WSAuthorization>
</soap12:Header>
<soap12:Body>
<ImportDrugTest xmlns="http://url.com/testing/">
<specimenID>int</specimenID>
<midasNumber>string</midasNumber>
<specimenComments>string</specimenComments>
<nonRXDrugsUsed>string</nonRXDrugsUsed>
<testCode>string</testCode>
<testDate>dateTime</testDate>
<testResult>string</testResult>
<collectionDate>dateTime</collectionDate>
<lastName>string</lastName>
<firstName>string</firstName>
<middleName>string</middleName>
<CRUDFlag>string</CRUDFlag>
</ImportDrugTest>
</soap12:Body>
</soap12:Envelope>
This is what I am getting
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/testing/">
<soap-env:header>
<ns1:wsauthorization />
</soap-env:header>
<soap-env:body>
<ns1:importdrugtest>
<ns1:specimenid>605431024</ns1:specimenid>
<ns1:midasnumber>7700MD2005000001.00</ns1:midasnumber>
<ns1:specimencomments>Miscellaneous</ns1:specimencomments>
<ns1:nonrxdrugsused>N/A</ns1:nonrxdrugsused>
<ns1:testcode>025000</ns1:testcode>
<ns1:testdate>2012-09-24</ns1:testdate>
<ns1:testresult>Negative</ns1:testresult>
<ns1:collectiondate>2012-09-25</ns1:collectiondate>
<ns1:lastname>Last</ns1:lastname>
<ns1:firstname>First</ns1:firstname>
<ns1:middlename>Middle</ns1:middlename>
<ns1:crudflag>C</ns1:crudflag>
</ns1:importdrugtest>
</soap-env:body>
</soap-env:envelope>
Here is my code. Note: I have already stared a new SoapClient() and regeived the token.
$ns = 'http://url.com/testing/';
// $headerParams = array('WSAuthorization'=>array('token'=>$token)); tried this also
$headerParams = array('token'=>$token);
$header = new SoapHeader($ns, 'WSAuthorization', $headerParams);
$client->__setSoapHeaders($header);
$param = array('ImportTest' => array(
'specimenID' => '0605431024',
'midasNumber' => '7700MD2005000001.00',
'county' => '03',
'site' => '00',
'specimenComments' => 'Miscellaneous',
'nonRXDrugsUsed' => 'N/A',
'testCode' => '025000',
'testDate' => '2012-09-24',
'testResult' => 'Negative',
'collectionDate' => '2012-09-25',
'lastName' => 'Last',
'firstName' => 'First',
'middleName' => 'Middle',
'CRUDFlag' => 'C'
));
$result = $client->__soapCall('ImportDrugTest', $param);
Update 12/31/14:
I modified the code and added print_r($header):
$ns = "http://url.com/testing/";
$headerParams = array('token'=>$token);
$header = new SoapHeader($ns, 'WSAuthorization', $headerParams);
print_r($header);
$client->__setSoapHeaders(array($header)); // even tried $client->__setSoapHeaders($header);
I get this:
SoapHeader Object
(
[namespace] => http://url.com/testing/
[name] => WSAuthorization
[data] => Array
(
[token] => UDjVSzGt9J4fKuRuoFHau3gy4CoLo//VlnuZv5oy5tjKPffIeSc+dx7EEDIfosVkVHDD0G/ZBANnCzPmRBo6CIusRL5rak5QdYI9jD7209c=
)
[mustUnderstand] =>
)
But __getLastRequest() gives me this:
<soap-env:header>
<ns1:wsauthorization />
</soap-env:header>
What am I missing?
This works:
$headerParams = array('Token' => $token);
$header = new SoapHeader($NameSpace, 'WSAuthorization', $headerParams, false);
The problem I was having was caused by the token not being parsed from the response.

create php SOAP request

i wanna create soap request as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.0">
<soapenv:Header/>
<soapenv:Body>
<ns:updateUser sequence="?">
<!--You have a CHOICE of the next 2 items at this level-->
<uuid>{74932749237942794729473927493829}</uuid>
<userid>?</userid>
<associatedGroups>
<!--Zero or more repetitions:-->
<userGroup>
<name>Standard CTI Enabled</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CTI Enabled</userRole>
</userRoles>
</userGroup>
<userGroup>
<name>Standard CCM End Users</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CCM End Users</userRole>
</userRoles>
</userGroup>
</associatedGroups>
</ns:updateUser>
</soapenv:Body>
</soapenv:Envelope>
I have this as my code so far:
$userId = "example#mydomain.com";
$retAccessWebex["UserUuid"] = "{74932749237942794729473927493829}"; //sample userUuid
$userGroup = array();
$userRoleCTI = array("Standard CTI Enabled");
$userGroup[] = array(
"name" => "Standard CTI Enabled",
"userRoles" => array(
"userRole" => $userRoleCTI,
)
);
$userRoleCCM = array("Standard CCM End Users");
$userGroup[] = array(
"name" => "Standard CCM End Users",
"userRoles" => array(
"userRole" => $userRoleCCM,
)
);
$param = array(
"uuid" => $retAccessWebex["UserUuid"],
"userid" => $userId,
"associatedGroups" => array(
array(
"userGroup" => $userGroup,
)
)
);
$mywsdl = "pathToSchemaWsdl/AXLAPI.wsdl";
$wsdl = "https://127.0.0.1:8443/axl/";
$client = new SoapClient($mywsdl,
array('trace' => true,
'exceptions' => true,
'location' => $wsdl,
'login' => 'administrator',
'password' => 'mtp455w0rd',
));
$response = $client->updateUser($param);
however, when executing, I get this error message:
Fatal error: Uncaught SoapFault exception: [Sender] SOAP-ERROR:
Encoding: object has no 'name' property
try to see what is in request
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest();

Categories