i'm trying to make a soap call to a web service to pass shipping data. Here is the request i'm sending so far:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://weblabeling.gls-italy.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
<env:Body>
<ns1:AddParcel env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<!-- bof shipping array --->
<XMLInfoParcel>
<Info>
<SedeGls>XXXX</SedeGls>
<CodiceClienteGls>XXXXX</CodiceClienteGls>
<PasswordClienteGls>XXXXXX</PasswordClienteGls>
<Parcel>
<CodiceContrattoGls>XXXXXX</CodiceContrattoGls>
<RagioneSociale>XXXXXX</RagioneSociale>
<!-- other stuff here -->
</Parcel>
</Info>
</XMLInfoParcel>
<!-- eof shipping array --->
</ns1:AddParcel>
</env:Body>
</env:Envelope>
this is instead what webservice is asking me
<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:Body>
<AddParcel xmlns="http://weblabeling.gls-italy.com/">
<XMLInfoParcel>string</XMLInfoParcel>
</AddParcel>
</soap12:Body>
</soap12:Envelope>
I always get as response xml format error.
What is wrong?
Shipping array is correct and match perfectly the request one.
Thanks in advance.
Edited:
Here is how i build xml:
//inseriamo i dati nei corretti array
$Label = array(
'XMLInfoParcel' => array(
'Info' => array(
'SedeGls' => $SedeGls,
'CodiceClienteGls' => $CodiceClienteGls,
'PasswordClienteGls' => $PasswordClienteGls,
'Parcel' => array(
'CodiceContrattoGls' => $cod_cont,
'RagioneSociale' => $rag_soc,
'Indirizzo' => $delivery_indirizzo,
'Localita' => $delivery_city,
'Zipcode' => $data['delivery_postcode'],
'Provincia' => $data['zone_code'],
'Bda' => '',
'DataDocumentoTrasporto' => '',
'Colli' => '1',
'Incoterm' => '',
'PesoReale' => '1,00',
'ImportoContrassegno' => $imp_cont,
'NoteSpedizione' => $data['customers_telephone'],
'TipoPorto' => 'F',
'Assicurazione' => $ass_ins,
'PesoVolume' => '',
'TipoCollo' => $tipo_collo,
'FrancoAnticipata' => '',
'RiferimentoCliente' => '',
'NoteAggiuntive' => '',
'CodiceClienteDestinatario' => '',
'Email' => '',
'Cellulare1' => $telefono_1,
'Cellulare2' => '',
'ServiziAccessori' => '',
'ModalitaIncasso' => $mod_inc
),),),
);
$dom = new DOMDocumentExt('1.0', 'utf-8');
$chiamta = $dom->loadArray($Label);
$dudy = $dom->saveXML();
#Iserni i put ---> only here, this is not in my code, i'm going to Test the online tool, i really don't see errors.
I still get error of xml format, any other clue guys?
Edited:
I just noticed my request has:
<ns1:AddParcel env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
while the required is:
<AddParcel xmlns="http://weblabeling.gls-italy.com/">
So i noticed also in envelope there is something different with namespaces.
Could it be the problem?
WSDL seems to not work on gls server, they did not provide any info in documentation about it.
Edited:
Maybe i'm dumb but this is the request xml schema:
So now shall i place more whitespace before ?
What do you think? and if so how?
You have three errors in your XML, but you can easily find them (and future ones) using xmllint (also online).
Basically, your XML comments ought to end with --> and not --->, and you should check tag opening/closing.
Also, the request is for <XMLInfoParcel>string</XMLInfoParcel>, but that is not what you're sending...?
Related
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
)];
I'm using PSWebServiceLibrary.php for prestashop and in the add function this is the code which send the xml request for parsning. I have
self::checkStatusCode($request['status_code']);
$res = trim($request['response'] );
var_dump($res);
return self::parseXML($request['response']);
And this is the output of var_dump :
string(1459) "<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer>
<id><![CDATA[220]]></id>
<id_default_group></id_default_group>
<id_lang xlink:href="http://elpakhsh.com/api/languages/2"><![CDATA[2]]></id_lang>
<newsletter_date_add><![CDATA[2017-07-12 10:50:46]]></newsletter_date_add>
<ip_registration_newsletter></ip_registration_newsletter>
<last_passwd_gen><![CDATA[2017-07-12 04:50:46]]></last_passwd_gen>
<secure_key><![CDATA[95bb810ab3d387bc7eb249030ec06233]]></secure_key>
<deleted></deleted>
<passwd><![CDATA[e95db4822affea261aad478059f75457]]></passwd>
<lastname><![CDATA[مشتری]]></lastname>
<firstname><![CDATA[مشتری]]></firstname>
<email><![CDATA[navid.abutorab#gmail.com]]></email>
<id_gender></id_gender>
<birthday></birthday>
<newsletter><![CDATA[1]]></newsletter>
<optin><![CDATA[1]]></optin>
<website></website>
<company></company>
<siret></siret>
<ape></ape>
<outstanding_allow_amount></outstanding_allow_amount>
<show_public_prices></show_public_prices>
<id_risk></id_risk>
<max_payment_days></max_payment_days>
<active><![CDATA[1]]></active>
<note></note>
<is_guest></is_guest>
<id_shop><![CDATA[1]]></id_shop>
<id_shop_group><![CDATA[1]]></id_shop_group>
<date_add><![CDATA[2017-07-12 10:50:46]]></date_add>
<date_upd><![CDATA[2017-07-12 10:50:46]]></date_upd>
<associations>
<groups nodeType="group" api="groups"/>
</associations>
</customer>
</prestashop>"
As you can see from the output, There is no whitespace at the beginning but I still got the error that says
HTTP XML response is not parsable: array ( 0 =>
LibXMLError::__set_state(array( 'level' => 3, 'code' => 64, 'column'
=> 7, 'message' => 'XML declaration allowed only at the start of the document ', 'file' => '', 'line' => 1, )), )
What's the problem?is there anything wrong with my xml ??I have validate it and it got no problem ..
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>
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!
Rate Quote
Rate quote request must be sent to the following URL:SomeIPaddress/cgibin/
map/RATEQUOTE
Here is a sample schema of the Rate Quote Request.
<?xml version="1.0" encoding="utf-8" ?>
- <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
- <soap12:Body>
- <request>
- <Details>
- <DetailItem>
<Weight>decimal</Weight>
<Class>decimal</Class>
</DetailItem>
</Details>
- <Accessorials>
- <AccessorialItem>
<Code>char</Code>
</AccessorialItem>
</Accessorials>
<BillingTerms>Char</BillingTerms>
<OriginCity>Char</OriginCity>
<OriginState>Char</OriginState>
<OriginZipcode>Char</OriginZipcode>
<DestinationCity>Char</DestinationCity>
<DestinationState>Char</DestinationState>
<DestinationZipcode>Char</DestinationZipcode>
<PalletCount>decimal</PalletCount>
<Customer>Char</Customer
I am using this coding for this but its not working showing errror previously i have used this method for many API's but i uesd to have .wsdl file:
<? $client = new SoapClient('http://208.51.75.23:6082/cgi-bin/map/RATEQUOTE',array( 'trace' => 1,'exceptions' => 0 ));
$params = array("Details" => array("DetailItem" =>array("Weight" =>"3","Class" =>"55")),
"Accessorials" => array("AccessorialItem"=>array("Code" =>"LIFTG")),
"BillingTerms" => "FEEP", //Billing Terms:Prepaid Collect
"OriginCity" => "Henrico",
"OriginState" => "VA",
"OriginZipcode" => "23229",
"DestinationCity" => "LOS ANGELES",
"DestinationState" => "CA",
"DestinationZipcode" => "90001",
"PalletCount" => "1",
"Customer" => "abc",
);
$return = $client->CreateResult->$params;
print_r($return);die;
?>
You can't, you need an IP Address or URL to connect to, or it needs to be contained in the WSDL file. Otherwise, you can never know where to connect to...