WSDL interpret supossed operation parameters - php

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>

Related

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!

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

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.

How do I create this xml with PHP's SoapClient?

From debugging another application, I found that it sends the following xml to a soap server (code parts in this example are minimized, the xml is about 200 lines long:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m0="http://schemas.ccs.nl/datacatalogus/modellen/modelrelatie">
<SOAP-ENV:Header>
<m:header xmlns:m="http://schemas.ccs.nl/soap">
<m:account>account</m:account>
<m:naam>naam_header</m:naam>
<m:wachtwoord>wachtwoord</m:wachtwoord>
<m:bedrijfsnummer>bedrijfsnummer</m:bedrijfsnummer>
<m:tussenpersoonnummer>tussenpersoonnummer</m:tussenpersoonnummer>
</m:header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<m:RelatieMuteren xmlns:m="http://schemas.ccs.nl/services/relatieservice">
<m:relatie pc="W">
<m0:adres>adres</m0:adres>
</m:relatie>
</m:RelatieMuteren>
</SOAP-ENV:Body>
Obviously, the part between <m0:adres></m0:adres> is a lot larger and corresponds to my data that is stored in an array. However, if I try to send the request using __soapCall, PHP builds the following request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.ccs.nl/datacatalogus/modellen/modelrelatie"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns2="http://schemas.ccs.nl/services/relatieservice" xmlns:ns3="http://schemas.ccs.nl/soap">
<SOAP-ENV:Header>
<ns3:header>
<ns3:account>account</ns3:account>
<ns3:naam>naam</ns3:naam>
<ns3:wachtwoord>wachtwoord</ns3:wachtwoord>
<ns3:bedrijfsnummer>bedrijfsnummer</ns3:bedrijfsnummer>
<ns3:tussenpersoonnummer>tussenpersoonnummer</ns3:tussenpersoonnummer>
</ns3:header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:RelatieMuteren>
<ns2:relatie pc="I">
<ns1:adres>Postbus 53</ns1:adres>
</ns2:relatie>
</ns2:RelatieMuteren>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can see, the second xml is quite different from the first. Can anyone explain me why it is different and how I can create the first type of xml?
I use the following code to do the request:
$client = new SoapClient( "http://www.cdsverzekeringen.nl/ws_prod/services/RelatieService.asmx?WSDL", array( 'trace' => 1 ) );
$aHeader = array(
'account' => "PRIVATE",
'naam' => "PRIVATE",
'wachtwoord' => "PRIVATE",
'bedrijfsnummer' => "PRIVATE",
'tussenpersoonnummer' => "PRIVATE",
);
$client->__setSoapHeaders( new SoapHeader( "http://schemas.ccs.nl/soap", 'header', $aHeader ) );
$vtResult = $client->__soapCall( "RelatieMuteren", array( $aRelatieInfo ) );
The $aRelatieInfo array is formatted like this:
array
'relatie' =>
array
'adres' => string 'Postbus 53' (length=10)
I hope someone can help me out. Thanks in advance!
How about using SoabVar API like this,
$aHeader = '
<m:header xmlns:m="http://schemas.ccs.nl/soap">
<m:account>account</m:account>
<m:naam>naam_header</m:naam>
<m:wachtwoord>wachtwoord</m:wachtwoord>
<m:bedrijfsnummer>bedrijfsnummer</m:bedrijfsnummer>
<m:tussenpersoonnummer>tussenpersoonnummer</m:tussenpersoonnummer>
</m:header>';
$soap_var_header = new SoapVar( $aHeader , XSD_ANYXML, null, null, null);
$client->__setSoapHeaders( new SoapHeader( "http://schemas.ccs.nl/soap", 'm', $soap_var_header ) );

PHP soap server double encoding html strings

I'm having a problem where my php soap webservice is double encoding strings. For example if I try to return the string O'Test, what I get is O&apos;Test. What I would have expected to see is O&apos;Test. It seems like what is happening is the & itself is getting encoded?
I've look through what phpinfo() returns (this is php version 5.1.6), but I don't see anything obvious.
My code to initialize the soap server uses arrays to automate the initialization of my functions and types but this is the gist of what I'm doing:
$server = new soap_server();
$server->configureWSDL('server', 'urn:sg');
$server->wsdl->addComplexType( 'testCall', 'complexType', 'struct', 'all', '', array( 'name' => 'testName', 'type' => 'xsd:string' ) );
$server->register( $fname,
array( 'request' => 'tns:TestCallRequest' ),
array( 'return' => 'tns:TestCallResponse' ),
'urn:sg',
'urn:sg#testCall' );
$server->service($HTTP_RAW_POST_DATA);
Here is the function represented by $fname above:
function testCall() {
$result = array();
$result[testName] = 'O\'Test';
return $result;
}
Here is the soap request and response that I see from a client perspective:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sg"><soapenv:Header/><soapenv:Body><urn:testCall soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><urn:TestCallRequest></urn:TestCallRequest></urn:testCall></soapenv:Body></soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:sg"><SOAP-ENV:Body><ns1:TestCallResponse xmlns:ns1="urn:sg"><return xsi:type="tns:TestCallResponse"><testName xsi:type="xsd:string">O&apos;Test</testName></return></ns1:TestCallResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Categories