PHP Soap Client receives incomplete data - php

I wrote very simple code to retrieve soap data:
$wsdl = 'https://...';
$client = new SoapClient($wsdl, ['trace' => true]);
$soap_parameters = [
'leveranciernaam' => 'xxx',
'leveranciersleutel' => 'yyy',
'brinnummer' => 'zzzz',
'schooljaar' => 2012
];
$response = $client->getLeerlingen($soap_parameters);
To my huge surprise, the return was different from the return i received while using a Java based GUI application.
Some fields in PHP SoapClient's response were consistently missing.
Just to make sure that things were not lost in translation to stdObjects, I used trace option to and extracted actual XMl from $client->__getLastResponse();
Still those fields were not there - very consistently over hundreds of records.
Windows Java based client's response:
<return>
<leerlingen>
<leerling>
<id>353226866</id>
<roepnaam>Evline</roepnaam>
...
<achternaam>Staalstra</achternaam>
<inschrijvingen>
<inschrijving>
<id>353226867</id>
<datumInschrijving>2007-08-20T00:00:00+02:00</datumInschrijving>
<schoolVanHerkomst>7138</schoolVanHerkomst>
<vervolgSchool>7138</vervolgSchool>
<onderwijsSoortBestemming>
<id>4085</id>
</onderwijsSoortBestemming>
</inschrijving>
</inschrijvingen>
</leerling>
...
</leerlingen>
<brins>
<brin>
<id>47187537</id>
<brinNummer>02YN02</brinNummer>
<schoolNaam>De Ambelt School V LZK</schoolNaam>
</brin>
...
</brins>
</return>
Response i get:
<return>
<leerlingen>
<leerling>
<id>353226866</id>
<roepnaam>Evline</roepnaam>
...
<achternaam>Staalstra</achternaam>
<inschrijvingen>
<inschrijving>
<id>353226867</id>
<datumInschrijving>2007-08-20T00:00:00+02:00</datumInschrijving>
<inschrijvingType>1766564</inschrijvingType>
</inschrijving>
</inschrijvingen>
</leerling>
...
</leerlingen>
</return>
PHP client does not get (or does not properly parse) any elements schoolVanHerkomst, vervolgSchool and onderwijsSoortBestemming in element inschrijving and it misses brins completely.
For brevity, I omitted other deeply nested elements that work just fine
Because expected results are dynamic, WDSL ( https://acceptatie.parnassys.net/bao/services/cxf/v1/generic?wsdl ) does not define ouput.
What is going on? It seems that PHP Soap client is less reliable than Java Soap clients

Related

Testing Symfony validation with Panther

I'm testing my validations and I send wrong values in all my input :
$crawler = $this->client->getCrawler();
$form = $crawler->selectButton('Créer')->form();
$form->setValues([
'Contractor[lastName]' => str_repeat('maxLength', self::OVER_MAX_LENGTH,),
'Contractor[firstName]' => str_repeat('maxLength', self::OVER_MAX_LENGTH,),
'Contractor[email]' => str_repeat('maxLength', self::OVER_MAX_LENGTH,).'#society.com',
'Contractor[phone]' => str_repeat('0', self::UNDER_MIN_LENGTH,),
'Contractor[password][password][first]' => 'first',
'Contractor[password][password][second]' => 'second',
'Contractor[status]' => 'admin.crud.user.field.choices.boss'
]);
$this->client->submitForm('Créer');
$this->client->waitFor('.invalid-feedback');
$this->client->waitForVisibility('.invalid-feedback');
$this->client->takeScreenshot('add.png');
$totalErrors = $crawler->filter('div.invalid-feedback')->count();
$errorExpected = 5;
$this->assertNotCount($totalErrors, [$errorExpected]);
When I test I ask to wait until the errors are displayed. Then I count the number of errors and I compare. The problem is when this line is test $totalErrors = $crawler->filter('div.invalid-feedback')->count(); I've got an error which say :
Facebook\WebDriver\Exception\StaleElementReferenceException: stale element reference: element is not attached to the page document.
In the screenshot, the errors are displayed.
I really don't understand why because I asked to wait for the element to be in the DOM and I had no errors.
Any idea ?
It's possible that the Crawler instance you have has a "stale" HTML in its state. I don't know the exact internals, but what helped me with a similar case was to get a fresh crawler from the Client object:
// some actions that redraws the Client HTML
$crawler = $client->getCrawler();
$totalErrors = $crawler->filter('div.invalid-feedback')->count();

Getting an error trying to pass data to web service method using PHP

I'm trying to use PHP to pass submitted form fields to a web service that will create a user record in our database. I know the web service is working because I have ColdFusion code that is able to successfully create a user account with submitted parameters from my local machine. However, I need to get this working in php since our site is built in Drupal (php). I also tried the wsclient (drupal module) but to no avail.
I came accross this post (How to make a PHP SOAP call using the SoapClient class) which is similar to what I'm trying to do, but I keep getting an error. Here is the code I'm working with. Also, I need to pass the security password to use the web service in order to use it.
class Create {
function Create($securityPassword)
{
$this->securityPassword = $securityPassword;
}
}
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$create = new Create("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); //web service password
$params = array(
"Create" => $create,
"Prefix" => "Mr",
"FirstName" => "John",
"LastName" => "Doe",
);
//print_r($params);
$response = $client->__soapCall('Create', array($params));
var_dump($response);
Here is the error I'm getting:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\wamp\www\sandbox\webservice2.php:23 Stack trace: #0 C:\wamp\www\sandbox\webservice2.php(23): SoapClient->__soapCall('Create', Array) #1 {main} thrown in C:\wamp\www\sandbox\webservice2.php on line 23
The method I'm trying to call is the "Create" method. You can see it exists in the wsdl url
I'd appreciate help in trying to successfully create a record using the web service via php.
This should allow it work.
XML
<Create xmlns="http://ibridge.isgsolutions.com/Account/">
<securityPassword>string</securityPassword>
<account>
<Id>string</Id>
<Status>string</Status>
<MemberType>string</MemberType>
<JoinDate>string</JoinDate>
<Prefix>string</Prefix>
<FirstName>string</FirstName>
<MiddleName>string</MiddleName>
<LastName>string</LastName>
<Suffix>string</Suffix>
<Designation>string</Designation>
<InformalName>string</InformalName>
<MajorKey>string</MajorKey>
<Title>string</Title>
<ExcludeFromDirectory>string</ExcludeFromDirectory>
<WebSite>string</WebSite>
<Company>string</Company>
<CompanyID>string</CompanyID>
<OrgCode>string</OrgCode>
<SourceCode>string</SourceCode>
<ExcludeFromMail>string</ExcludeFromMail>
<Category>string</Category>
<Gender>string</Gender>
<BirthDate>string</BirthDate>
<WorkPhone>string</WorkPhone>
<Fax>string</Fax>
<TollFree>string</TollFree>
<HomePhone>string</HomePhone>
<Email>string</Email>
<Chapter>string</Chapter>
<FunctionalTitle>string</FunctionalTitle>
<PaidThru>string</PaidThru>
<WebLogin>string</WebLogin>
<Password>string</Password>
<SecurityGroup>string</SecurityGroup>
<ExpirationDate>string</ExpirationDate>
<StaffUser>string</StaffUser>
<WebUser>string</WebUser>
<Demographics>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
</Demographics>
</account>
</Create>
code
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$params = [
"Create" => [
'securityPassword' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'account' => [
'Prefix' => 'Mr',
'FirstName' => 'John',
'LastName' => 'Doe'
]
]
];
$response = $client->__soapCall('Create', $params)->CreateResult;
var_dump($response);

php soap - send request for multidimensional array

First up, I'm trying to send a soap request using PHP SOAP and the XML that the service accepts is as shown below.
<U_MemberReservedTransaction xmlns="http://tempuri.org/">
<UserID>string</UserID>
<password>string</password>
<memberReservedTransactionRequest>
<memberReservedTransactions>
<ReservedType>string</ReservedType>
<Firstname>string</Firstname>
<Surname>string</Surname>
<IcNew>string</IcNew>
</memberReservedTransactions>
<memberReservedTransactions>
<ReservedType>string</ReservedType>
<Firstname>string</Firstname>
<Surname>string</Surname>
<IcNew>string</IcNew>
</memberReservedTransactions>
</memberReservedTransactionRequest>
</U_MemberReservedTransaction>
Just to summarize what the service is expecting, the service is to receive an array of memberReservedTransactions. My SOAP request call looks like below currently.
$client->callService('U_MemberReservedTransaction', array(
'UserID'=>'test1',
'password'=>'password',
'memberReservedTransactionRequest' => array(
'memberReservedTransaction' => array (
array(
'ReservedType'=>'Renew',
'Firstname'=>'',
'Surname'=>'',
'IcNew'=>''
)
)
)
));
As for what i'm expecting in return is a multidimensional array but my concern now is getting my request accepted.
Note : I'm getting a 500 Internal Server Error
Please help :<

ZF2 SOAP "Procedure not present" Error

I'm having serious trouble to solve this issue. I got an APP with 3 modules that got different services to provide by SOAP. What happens is that 2 of them are getting this response:
SoapFault
File:
/var/www/empreendimentos/vendor/zendframework/zendframework/library/Zend/Soap/Client.php:10
Message:
Procedure not present
I already double checked, and the names of the functions are right and I use the method getFunctions. This is the return from getFunctions():
array
0 => string 'Array getCliAll(anyType $filter)' (length=32)
1 => string 'Array insertCli(anyType $data)' (length=30)
2 => string 'Array editCli(anyType $data, anyType $id)' (length=41)
3 => string 'void setServiceLocator(anyType $serviceLocator)' (length=47)
4 => string 'void getServiceLocator()' (length=24)
My handle methods look like this:
public function handleWSDL() {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('\Cli\Service\CliService');
$autodiscover->setUri($this->_URI);
$wsdl = $autodiscover->generate();
$wsdl = $wsdl->toDomDocument();
// geramos o XML dando um echo no $wsdl->saveXML()
echo $wsdl->saveXML();
}
public function handleSOAP() {
$soap = new \Zend\Soap\Server($this->_WSDL_URI);
$soap->setWSDLCache(false);
$classHandle = new CliService();
$classHandle->setServiceLocator($this->getServiceLocator());
$soap->setClass($classHandle);
$soap->handle();
}
I get no errors on the server side. Only this response for all the methods. What is wrong?
UPDATE:
Turns out it's a "Problem" of the ZF2 config. overload. I had my modile.config.php to hold my WSDL and URI information, but used the same label for the config on the file. The overload was making every WSDL and URI the same, and giving me the problem.
Like this:
Emp Module modile.config.php
'service_url' => array(
"wsdl" => 'http://localhost/empreendimentos/public/emp/service?wsdl',
"return" => 'http://localhost/empreendimentos/public/emp/service',
),
Emp Module modile.config.php
'service_url' => array(
"wsdl" => 'http://localhost/empreendimentos/public/cli/service?wsdl',
"return" => 'http://localhost/empreendimentos/public/cli/service',
),
Anyone know why this is like this? is it suposed to mix module configs?
Had this problem yesterday, found the answer was in the server wsdl call.
The server calls its own wsdl to introspect the available methods. If your wsdl url is wrong, it sees what methods are available in another server and says 'Procedure not present'.
In my case the AdmintoolsController had the line
$wsdl_url = 'http://' . $_SERVER['HTTP_HOST'] . '/news/?wsdl';
so it was looking in the News service for the method.
Change it to
$wsdl_url = 'http://' . $_SERVER['HTTP_HOST'] . '/admintools/?wsdl';
and it works fine.
I searched Google for hours looking for this fix, and my colleague looked at the code and spotted it straight away.
Hope this helps
John
Also try to do the below changes and then check if it works:
Remove the files starting with "wsdl-" in the tmp folder of your zend server.
Make a php setting: phpSettings.soap.wsdl_cache_enabled = 0 in your application.ini file.

DHL, Soap, PHP - not understanding

I have to make a SOAP-Request with PHP to the DHL Carrier Service to generate batch labels. Somehow, I can't understand how it works. I wrote this code:
<?php
require_once('lib/Zend/Soap/Client.php');
require_once('lib/Zend/Soap/Client/Common.php');
$client = new Zend_Soap_Client('http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp'
)
);
$location = 'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp';
$request = '
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cis="http://dhl.de/webservice/cisbase" xmlns:de="http://de.ws.intraship">
<soap:Header><cis:Authentification><cis:user>magento</cis:user><cis:signature>m1a2$!</cis:signature><cis:accountNumber>5000000000</cis:accountNumber><cis:type>0</cis:type></cis:Authentification>
</soap:Header>
<soap:Body><de:CreateShipmentDDRequest>
<cis:Version>
<cis:majorRelease>1</cis:majorRelease>
<cis:minorRelease>0</cis:minorRelease></cis:Version><ShipmentOrder><SequenceNumber>1</SequenceNumber><Shipment><ShipmentDetails><ProductCode>EPN</ProductCode><ShipmentDate>2012-10-03</ShipmentDate><DeclaredValueOfGoods>10.2</DeclaredValueOfGoods><DeclaredValueOfGoodsCurrency>EUR</DeclaredValueOfGoodsCurrency><cis:EKP>5000000000</cis:EKP><Attendance><cis:partnerID>01</cis:partnerID></Attendance><CustomerReference>Auftrag 12883884</CustomerReference><ShipmentItem><WeightInKG>12</WeightInKG><LengthInCM>1</LengthInCM><WidthInCM>1</WidthInCM><HeightInCM>10</HeightInCM><PackageType>PK</PackageType></ShipmentItem><Service><ShipmentServiceGroupIdent><ReturnReceipt>false</ReturnReceipt></ShipmentServiceGroupIdent></Service><Service><ShipmentServiceGroupIdent><Personally>false</Personally></ShipmentServiceGroupIdent></Service><Service><ServiceGroupDHLPaket><Multipack>False</Multipack></ServiceGroupDHLPaket></Service><BankData><cis:accountOwner>DHL.de</cis:accountOwner><cis:accountNumber>1234567891</cis:accountNumber><cis:bankCode>87050000</cis:bankCode><cis:bankName>Sparkasse Chemnitz</cis:bankName><cis:iban>DE34870500001234567891</cis:iban><cis:note>Notiz Bank</cis:note><cis:bic>CHEKDE81XXX</cis:bic></BankData></ShipmentDetails><Shipper><Company><cis:Person><cis:firstname></cis:firstname><cis:lastname>Deutsche Post IT BRIEF GmbH</cis:lastname></cis:Person></Company><Address><cis:streetName>Heinrich-Brüning-Str.</cis:streetName><cis:streetNumber>7</cis:streetNumber><cis:Zip><cis:germany>53113</cis:germany></cis:Zip><cis:city>Bonn</cis:city><cis:Origin><cis:countryISOCode>DE</cis:countryISOCode></cis:Origin></Address><Communication><cis:phone>3935644</cis:phone><cis:email>dhl#dhl.com</cis:email><cis:contactPerson>IT Systeme Marketing Vertrieb</cis:contactPerson></Communication></Shipper><Receiver><Company><cis:Company><cis:name1>DHL Vertriebs GmbH Co. OHG</cis:name1></cis:Company></Company><Address><cis:streetName>Neue Poststr.</cis:streetName><cis:streetNumber>1</cis:streetNumber><cis:Zip><cis:other>08496</cis:other></cis:Zip><cis:city>Neumark</cis:city><cis:Origin><cis:countryISOCode>DE</cis:countryISOCode></cis:Origin></Address><Communication><cis:phone>3935655</cis:phone><cis:email>dhl#dhl.com</cis:email><cis:contactPerson>CIS 1J4</cis:contactPerson></Communication></Receiver><ExportDocument><InvoiceType>proforma</InvoiceType><InvoiceDate>2012-10-03</InvoiceDate><InvoiceNumber>444444</InvoiceNumber><ExportType>1</ExportType><ExportTypeDescription>für Sonstiges</ExportTypeDescription><CommodityCode>8888888</CommodityCode><TermsOfTrade>CIP</TermsOfTrade><Amount>2000</Amount><Description>777777</Description><CountryCodeOrigin>DE</CountryCodeOrigin><AdditionalFee>3.12</AdditionalFee><CustomsValue>2.23</CustomsValue><CustomsCurrency>EUR</CustomsCurrency><PermitNumber>666666</PermitNumber><AttestationNumber>?</AttestationNumber><ExportDocPosition><Description>Harddisk</Description><CountryCodeOrigin>DE</CountryCodeOrigin><CommodityCode>123456</CommodityCode><Amount>200</Amount><NetWeightInKG>1</NetWeightInKG><GrossWeightInKG>1.2</GrossWeightInKG><CustomsValue>200</CustomsValue><CustomsCurrency>EUR</CustomsCurrency></ExportDocPosition></ExportDocument></Shipment><LabelResponseType>URL</LabelResponseType></ShipmentOrder></de:CreateShipmentDDRequest></soap:Body></soap:Envelope>
';
$clientCommon = new Zend_Soap_Client_Common($client, 'http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp'
));
$response = $client->_doRequest($clientCommon, trim($request), $location, 'createShipmentDD', SOAP_1_1);
print_r($response);
?>
The XML code is copied from the DHL test tool, the access data are standard test data, which should actually always work. But I always become a "Wrong login data"-message. Why can it be?
I tried to find something out with the SoapUI programm but I don't seem to understand how all this stuff work.
Can you please give me some help?
The URL you are trying sending your SOAP-Request to (https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp) is not used as an Web Service endpoint - it is the Single-Sign-On URL for logging in your customer to the DHL Intraship Customer Portal (you can submit parceldata manually there).
The endpoint for the Web Service is http://test-intraship.dhl.com/ws/1_0/de/ISService (Source: https://entwickler.dhl.de/group/ep/webservices/intraship/quick-start)
You may need more information from DHL
https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp
To Login this URL you need User name and password, This information is other than cis:Authentification section you passed in soap:Header node.
This new User name and password you need to set in new "Zend_Soap_Client_Common" object.

Categories