SOAP Request send empty body - php

I can't find out where is the problem, I have prepared an XML for sending through the SOAP Client like so:
$client = new SoapClient($url, array(
'trace' => true,
"style" => SOAP_RPC,
"use" => SOAP_ENCODED
));
$response = $client->sendItems($xml);
var_dump($client->__getLastRequest());
var_dump shows me string(233) " ", but when I'm testing it throught the PHPStorm Rest Client testing tool, it shows me this:
string(233) "<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://externalsite.com/ltm/"><SOAP-ENV:Body><ns1:sendItemsRequest/></SOAP-ENV:Body></SOAP-ENV:Envelope>
"
There are no content inside the body. I triple-checked that my $xml contains the full XML with bodycontent.
Anyone got similiar problem before or have some idea what's going on ?
==== UPDATED ====
Here is the XML Content:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ltm="http://externalsite.com/ltm/">
<soapenv:Header/>
<soapenv:Body>
<ltm:sendItemsRequest>
<ItemsToAdd>
<ItemToAdd>
<description>DEMO DESCRIPTION text</description>
<url>http://localhost/media/items/0000000001.jpg</url>
<brand>BRANDTEST</brand>
<status>creation</status>
<statusDate>1423209737</statusDate>
<beginDate>1406844000</beginDate>
<endDate>1730329200</endDate>
<targets>
<barcode>1234567891011</barcode>
<barcode>9876543210123</barcode>
</targets>
<medias>
<media>
<retailer>RETAILERTEST</retailer>
<format>dummyformat</format>
</media>
</medias>
</ItemToAdd>
</ItemsToAdd>
</ltm:sendItemsRequest>
</soapenv:Body>

Related

SOAP request with soapenv

I have the following code for connecting to a soap client. I am struggling hard to find how to create a proper soap request.
$soap = new SoapClient($apiWsdl,
array("soap_version" => SOAP_1_1,
"trace" => 1));
var_dump($soap);
echo $soap->__getLastResponse();
try{
$data = $soap->login($apiUser,$apiKey);
}
catch (SoapFault $soapFault) {
echo "Request :<br>", htmlentities($soap->__getLastRequest()), "<br>";
echo "Response :<br>", htmlentities($soap->__getLastResponse()), "<br>";
}
I get the following XML built:
<?xml version="1.0" encoding="UTF-8"?> \<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" 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/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:login><username xsi:type="xsd:string">XXXXXXX</username><apiKey xsi:type="xsd:string">XXXXXXXX</apiKey></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>
Which returns be a forbidden access.
However the server is accepting only request of the following form
<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:Magento">
<soapenv:Header/>
<soapenv:Body>
<urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<username xsi:type="xsd:string">XXXXXXX</username>
<apiKey xsi:type="xsd:string">XXXXXX</apiKey>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>
Can somebody please let me know what mistake I am making in the code.
It looks like you have a typo right after the XML tags. There is a backslash that should not be there. This could trigger your errors.
HTH, Jim

SOAP envelope with header authentication call php

I have to consume a webservice, but can't find a proper way to create the call.
This is the xml the company provide as example
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Qpay.POS.Gateway.ServiceContracts" xmlns:urn1="urn:Qpay.POS.Gateway.DataContracts">
<soapenv:Header/>
<soapenv:Body>
<urn:GetProvidersRequest>
<!--Optional:-->
<urn:Header>
<urn1:CertPublicKey>XX-XX-XX-XX-XX</urn1:CertPublicKey>
<!--Optional:-->
<urn1:UIID>XX</urn1:UIID>
<urn1:User>XXXX</urn1:User>
</urn:Header>
</urn:GetProvidersRequest>
</soapenv:Body>
</soapenv:Envelope>
Tried using this:
$soapURL = "https://pos.qpay123.biz/dBar/Gateway.svc?" ;
$soapParameters = Array('UIID' => "63", 'User' => "System") ;
$soapFunction = "GetProvidersRequest" ;
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction) ;
var_dump($soapResult);
But i get a false as var dump, can you point me on the right direction to solve it?
Thanks

PHP SOAP empty response

I am trying to access to a soap interface with soapui. Everything works fine:
Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soc="www.example.com">
<soapenv:Header/>
<soapenv:Body>
<soc:getMailboxes>
<userId>512</userId>
</soc:getMailboxes>
</soapenv:Body>
</soapenv:Envelope>
Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getMailboxesResponse xmlns="http://www.example.com">
<getMailboxesReturn>
<mailboxes>
<mailboxes>
<administratorNumbers/>
<administratorUsers>
<administratorUsers>512</administratorUsers>
</administratorUsers>
<allowsSuppressedNumbers>true</allowsSuppressedNumbers>
<deactivatedByAdmin>false</deactivatedByAdmin>
<deactivatedByUser>false</deactivatedByUser>
<mailNotificationActive>true</mailNotificationActive>
<name>speech box</name>
<notificationNumber xsi:nil="true"/>
<number>123123123</number>
<pin xsi:nil="true"/>
<recordConferenceCallActive>false</recordConferenceCallActive>
<sendSmsCount>0</sendSmsCount>
<sendSmsLimit>0</sendSmsLimit>
<smsNotificationActive>false</smsNotificationActive>
<tag xsi:nil="true"/>
<type>CLASSIC</type>
<voicemailEnabled>false</voicemailEnabled>
<whitelistedNumbers/>
</mailboxes>
</mailboxes>
<responseCode>
<ID>0</ID>
<name>OK</name>
</responseCode>
</getMailboxesReturn>
</getMailboxesResponse>
</soapenv:Body>
</soapenv:Envelope>
I tried this code to receive the same result:
$client = new SoapClient($soapURL,array('login' => "...",
'password' => "...",
'trace' => 1,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
$response = $client->getMailboxes(512);
echo var_dump(get_object_vars($response));
and I got this result:
array(2) {
["mailboxes"]=>
object(stdClass)#4 (0) {
}
["responseCode"]=>
object(stdClass)#5 (2) {
["ID"]=>
int(0)
["name"]=>
string(2) "OK"
}
}
I supposed a response with some values like in the soapui response (like object(stdClass)#5)? If I am sending a wrong userID, I get the right error message. Can anyone help me?
Update 1:
The getMailboxes method creates this code:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com">
<SOAP-ENV:Body>
<ns1:getMailboxes>
<userId>512</userId>
</ns1:getMailboxes>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Update 2:
if I use this code:
$response = $client->getMailboxes(["userId"=>512]);
I get this soap code. The userId should be 512, not 1.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="www.example.com">
<SOAP-ENV:Body>
<ns1:getMailboxes>
<userId>1</userId>
</ns1:getMailboxes>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
I got the soap code with:
echo "REQUEST:\n" . $client->__getLastRequest()
This call is incorrect:
$response = $client->getMailboxes(512);
Notice in your original XML, you are telling it what 512 means? Same goes for PHP, you have to identify the parameters that you send by using an associative array:
$response = $client->getMailboxes(["userId"=>"512"]);

Soap PHP : double XML tag

Hye
I'm trying to use a WebService with SOAP in PHP. But the SoapVar creates my DOM XML with double XML tag
My code :
$xmlContent = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:com="http://schemas.datacontract.org/2004/07/Commun.Metier">
<soapenv:Header/>
<soapenv:Body>
<tem:SendData> ....';
$soapClient = new SoapClient("URL OF THE WSDL", array('trace' => 1, 'location' => 'URL OF THE SERVICE', 'uri' => 'URL OF THE SERVICE'));
$myXML = new SoapVar($xmlContent, XSD_ANYXML);
try {
$result = $soapClient->__soapCall("SendData", array('SendData' => $myXML));
} catch (Exception $e) {
var_dump($e);
}
The problem is that I have an exception Bad request because the XML I'm sending haves 2 XML tags and Soap Enveloppe :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body><?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:com="http://schemas.datacontract.org/2004/07/Commun.Metier">
<soapenv:Header/>
<soapenv:Body>
<tem:SendData>
How can I cancel this double tag ?
Thanks

SOAP Request No Response

Can you help me out or point me in the right direction, I'm trying to perform a soap request to a WSDL feed but I'm not getting anything back.
When I use standard XML everything seems to work OK - how would I write the following into an array:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SupplierDirectorySearch xmlns="SOAPREQUEST">
<SupplierSearchDetails ClassVersion="1.0">
<Identification>
<SchemeOperatorRef>59582</SchemeOperatorRef>
<SecurityToken>MYTOKEN</SecurityToken>
</Identification>
<ApprovedServices ServiceRepair="Y" MOT="" Tyres="" CollectionDelivery="" CourtesyCar="" WhileUWait="" Callout24Hour="" BreakdownCover="" CollectionDeliveryNotes="" CourtesyCarNotes="" Inspections=""/>
<SupplierLocation>BB1</SupplierLocation>
<SearchRadiusMiles>300</SearchRadiusMiles>
<Preference>P</Preference>
<MaxReturnNumber>5</MaxReturnNumber>
<PageNo>0</PageNo>
</SupplierSearchDetails>
</SupplierDirectorySearch>
</soap:Body>
</soap:Envelope>';
I've written the following soap request:
$client = new SoapClient("URL?WSDL", $option);
$res = $client->SupplierDirectorySearch(
array('SupplierSearchDetails'=>
array('Identification' => array('SchemeOperatorRef'=>'61', 'SecurityToken'=>'MYTOKEN'),
'ApprovedServices' => array(
'ServiceRepair'=>'Y',
'MOT'=>'',
'Tyres'=>'',
'CollectionDelivery'=>'',
'CourtesyCar'=>'',
'WhileUWait'=>'',
'Callout24Hour'=>'',
'BreakdownCover'=>'',
'CollectionDeliveryNotes'=>'',
'CourtesyCarNotes'=>'',
'Inspections'=>'',
),
'SupplierLocation' => 'BB1',
'SearchRadiusMiles' => '2',
'Preference' => 'P',
'MaxReturnNumber' => '5',
'PageNo' => '0'
)
)
);
Nothing is coming back, I've enabled the trace and this is what's getting passed in the request:
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="OneLink_ServiceBookingComponent">
<SOAP-ENV:Body><ns1:SupplierDirectorySearch>
<ns1:SupplierSearchDetails>
<ns1:Identification>
<ns1:SchemeOperatorRef>61</ns1:SchemeOperatorRef>
<ns1:SecurityToken>MYTOKEN</ns1:SecurityToken>
</ns1:Identification>
<ns1:SupplierLocation>BB1</ns1:SupplierLocation>
<ns1:SearchRadiusMiles>2</ns1:SearchRadiusMiles>
<ns1:Preference>P</ns1:Preference>
<ns1:ApprovedServices ServiceRepair="Y" MOT="" Tyres="" CollectionDelivery="" CourtesyCar="" WhileUWait="" Callout24Hour="" BreakdownCover="" CollectionDeliveryNotes="" CourtesyCarNotes="" Inspections=""/>
<ns1:MaxReturnNumber>5</ns1:MaxReturnNumber>
<ns1:PageNo>0</ns1:PageNo>
</ns1:SupplierSearchDetails>
</ns1:SupplierDirectorySearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Can anyone shed any light on this, it's racking my brain!!
I've just been looking, do you think I will have to code the section like this:
<?php
$amount['_'] = 25;
$amount['currencyId'] = 'GBP';
$encodded = new SoapVar($amount, SOAP_ENC_OBJECT);
?>
Scott

Categories