Passing xml value as array to soap client PHP - 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!

Related

Multidimensional Array with PHP Soap Client

I'm trying to create a SOAP Client, but I need to send a multi-dimensional array (I think) as requested in the documentation, example below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.senior.com.br">
<soapenv:Body>
<ser:ColaboradoresAdmitidos>
<user>String</user>
<password>String</password>
<encryption>Integer</encryption>
<parameters>
<NumEmp>Integer</NumEmp>
<AbrTipCol>String</AbrTipCol>
<IniPer>DateTime</IniPer>
<FimPer>DateTime</FimPer>
</parameters>
</ser:ColaboradoresAdmitidos>
</soapenv:Body>
</soapenv:Envelope>
I create a array like this:
$arguments = [
'user' => 'xxxxx',
'password' => 'xxxxxxxxxx',
'encryption' => 0,
'parameters' => array(
'NumEmp' => 1,
'AbrTipCol' => '1',
'IniPer' => '01/01/2019',
'FimPer' => null
),
];
$client = new SoapClient($url, array('trace' => 1));
dd($arguments, $client->__soapCall("colaboradoresAdmitidos", $arguments), $client->__getLastRequest());
However in the request, it seems that it does not accept the array, in fact I did some tests, and in addition to the first 3 parameters, but none enter the generated XML.
I already made the array in different ways, and changed the parameter value, but it always returns as below:
<?xml version="1.0" encoding="UTF-8"?>\n
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://services.senior.com.br">
<SOAP-ENV:Body>
<ns1:ColaboradoresAdmitidos>
<user>xxxxxxx</user>
<password>xxxxxxxxx</password>
<encryption>0</encryption>
<parameters/>
</ns1:ColaboradoresAdmitidos>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Someone could help me, because the server understands that the parameter is missing, so I can't execute the query.
Searching the internet, I discovered a lot of people with this problem and who couldn't solve it. I discovered the error.
This happens when the parameters do not match those registered in the WSDL. in my case: the documentation mentions the parameters with a capital letter, however, I had to use it with a small letter.
It seems that the parameter key has to be the same value as the one registered in wsdl.
ex:
$arguments = [
'user' => 'xxxxx',
'password' => 'xxxxxxxxxx',
'encryption' => 0,
'parameters' => array(
'numEmp' => 1,
'abrTipCol' => '1',
'iniPer' => '01/01/2019',
'fimPer' => null
)];

WSDL interpret supossed operation parameters

I'm trying to invoque this operation getCountries but I can't figure out reading the WSDL file wich parameters are needed and in which structured way:
http://webservice.nizacars.es/Rentway_WS/getCountries.asmx?WSDL
I've already tried with:
$this->soap_client->getCountries(
array(
'countriesRequest' => array(
'companyCode' => $this->login,
'allCountries' => true
)
)
)
$this->soap_client->getCountries(
array(
'companyCode' => $this->login,
'allCountries' => true
)
)
$this->soap_client->getCountries(
'companyCode' => $this->login,
'allCountries' => true
)
But it seems I'm not matching the specs, since I'm getting a "[Server was unable to process request. ---> Object reference not set to an instance of an object.]"
The final request with SoapClient::__getLastRequest is:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.jimpisoft.pt/Rentway_Reservations_WS/getCountries">
<SOAP-ENV:Body>
<ns1:getCountries/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Edit, Solution:
$data = array(
'getCountries' => array(
'objRequest' => array(
'companyCode' => $this->login,
'allCountries' => true
)
)
);
$result = #$this->_client->__call('getCountries',$data);
wich parameters are needed and in which structured way:
You can use the soapUI-tool for generating a valid soap-request and response.
I propose to compare your soap-request (by logging it) with the one generated by soapUI:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:get="http://www.jimpisoft.pt/Rentway_Reservations_WS/getCountries">
<soap:Header/>
<soap:Body>
<get:getCountries>
<!--Optional:-->
<get:objRequest>
<!--Optional:-->
<get:companyCode>?</get:companyCode>
<get:allCountries>?</get:allCountries>
</get:objRequest>
</get:getCountries>
</soap:Body>
</soap:Envelope>

PHP Soap And .Net Dataset

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!

php soapclient Array to string conversion

I have an array a couple of levels deep in my SOAP request like below. When I run my SoapRequest I get Notice (8): Array to string conversion and my XML response does not convert the Array in RTrans to XML and I have no idea why. How I am creating the SOAP request and the XML version of it can be found below.
The Request:
$r['request'] = array(
'request' => array(
'user' => 'test',
'password' => 'test',
'RTrans' => array(
'Transactions' => array(
'Criteria' => array(
'Name' => 'Thomas'
)
)
)
)
);
try{
$response = $this->apiClient->DoQuery($r);
}
catch(Exception $e){
debug($e);
}
The XML Version
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://webServices/">
<SOAP-ENV:Body>
<ns1:DoNormalEnquiry>
<request>
<username>test</usernmae>
<password>test</password>
<RTrans>Array</RTrans>
</request>
</ns1:DoNormalEnquiry>
</SOAP-ENV:Body>
I think RTrans is defined as a String. Please have a look at the wsdl file.
Maybe thats the reason you got "Array" in the xml.
To send an array to your soapservice you could convert it to json.
json_encode( array('Transactions' => array('Criteria' => array('Name' => 'Thomas')));
or define a complex datatype.
Maybe SoapVar will help you.

PHP SOAP Client Values and Attributes Not Loading

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');'

Categories