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.
Related
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 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,
],
],
],
]
);
I got an issue here. I am trying make a request to a Web Appi: http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL
And I am sending a request to insertPodData();
I am using PHP and SOAP.
I am succesfull at connecting and giving the correct credentials. However I am not able to send a Dataset (cause I do not know the right way), so i get an empty dataset.
Datasets are for .NET lang. So it is kind of tricky with the php.
I tried already to send it as an array, i still get an empty result.
Here are some coding.
PHP:
$dataset = array(
'schema' => array(
'Enter_Branch_Id' => $speedex_branch_id,
'SND_Customer_Id' => $speedex_cust_id,
'SND_Agreement_Id' => $speedex_appi_key,
'RCV_Name' => 'Test',
'RCV_Addre1' => 'Test Adress',
'RCV_Zip_Code' => '54636',
'RCV_City' => 'Thessaloniki',
'RCV_Country' => 'Greece',
'RCV_Tel1' => '*******',
'Voucher_Weight' => '0',
),
'any' => ''
);
try {
$soap = new SoapClient("http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL",array('trace' => true));
$oAuthResult = $soap->insertPodData(
array(
'username' => $speedex_usrn,
'password' => $speedex_psw,
'VoucherTable' => $dataset,
'_tableFlag' => 3
)
);
$resultVoucher = $oAuthResult;
print_r($resultVoucher);
echo '<br>';
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";
die();
}catch(SoapFault $fault) {
die('<h1>Ooooops something is broken. Refresh or contact module creator </h1><br>'.$fault);
}
This is returning this result
RESULT: stdClass Object ( [insertPodDataResult] => 1 [newVoucherTable] => stdClass Object ( [schema] => [any] => ) )
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:insertPodData>
<ns1:username>****</ns1:username>
<ns1:password>****</ns1:password>
<ns1:VoucherTable>********************TestTest Adress54636ThessalonikiGreece********</ns1:VoucherTable>
<ns1:_tableFlag>3</ns1:_tableFlag>
</ns1:insertPodData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can observe the Dataset is not created and all the values are passed with out a reference.
Any ideas clues? Thanks in advance!
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.
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');'