I need to make a SOAP request and get a response back, but I have no idea how SOAP works. I tried to search for it and everything is so confusing.
I need to make an authentication request here like this :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dir="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
<soapenv:Header/>
<soapenv:Body>
<dir:Authenticate>
<!-- Optional: -->
<dir:authenticateRequest BranchCode="abcde" UserName="user" Password="password" Application="application" Client="?">
<dir:BranchID>1</dir:BranchID>
</dir:authenticateRequest>
</dir:Authenticate>
</soapenv:Body>
</soapenv:Envelope>
And get an response after that, but have no idea how to do it. I searched and found some similar questions, but can not get any response.
What I am doing is this :
$send = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dir="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
<soapenv:Header/>
<soapenv:Body>
<dir:Authenticate>
<!-- Optional: -->
<dir:authenticateRequest BranchCode="abcde" UserName="user" Password="password" Application="application" Client="?">
<dir:BranchID>1</dir:BranchID>
</dir:authenticateRequest>
</dir:Authenticate>
</soapenv:Body>
</soapenv:Envelope>';
$soapUrl ="http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl";
$soapClientVar = new SoapClient("http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl");
$resp = $soapClientVar->Authenticate($send);
var_dump($resp);
I know that 99% I totally wrong of what should I do. Can someone please help me understand what exactly should I do and make this SOAP work?
TIA
The WSDL sets up the SoapClient:
http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl
and tells the client what to expect in terms of methods to call on the SOAP service. SoapClient takes care of creating what you see in $send.
Instead of sending raw SOAP (which SoapClient will do for you), you work at the method level. From the WSDL the Authenticate() method takes a parameter of type tns:AuthenticateRequest which contains BranchCode, UserName etc. and returns an object of type tns:AuthenticateResponse, containing tns:ResultBase which contains the actual result Success, Narrative etc.
this might get you towards your solution:
$soapClientVar = new SoapClient("http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl");
$params = array(
"BranchCode" => $BranchCode,
"UserName" => $UserName,
"Password" => $Password,
"Application" => $Application,
"Client" => $Client
);
$response = $soapClientVar->__soapCall("Authenticate", array($params));
Related
With PHP, I need to send a SOAP request with a parameter (Hash) in the footer. I'm using SoapClient but I can not figure out how to do this, neither in internet searches, nor in documentation.
This is the envelope I used in the SoapUI tool to test:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abc="" xmlns:abc1="" xmlns:abc2="">
<soapenv:Header/>
<soapenv:Body>
<abc:Method>
<!--Optional:-->
<abc:request>
<abc1:Header>
<abc1:Username>Username</abc1:Username>
<abc1:Password>Password</abc1:Password>
<!--Optional:-->
<abc1:PublicKeyUid></abc1:PublicKeyUid>
</abc1:Header>
<abc1:Body>
<abc2:Id></abc2:Id>
</abc1:Body>
<abc1:Footer>
<abc1:Hash></abc1:Hash>
</abc1:Footer>
</abc:request>
</abc:Method>
</soapenv:Body>
</soapenv:Envelope>
There is The SoapHeader class e the SoapClient::__setSoapHeaders method but I find nothing related to the footer.
I do not have access to the server and should follow this structure mentioned above.
What I need to know is how to send the HASH parameter that is inside the footer with SoapClient.
Thanks in advance for any help or suggestion.
As IMSoP and axiac have commented, the footer (<abc1: Footer>) is just a sub-structure of the envelop body and not a standard XML envelop element. I had not realized this and so I did not find it in the documentation.
So to send HASH to the requested structure, I need to pass a multidimensional array on the body element. The code looks like this:
$arrParameters = [
'request'=>[
'Header'=>[
'Username'=>$strUsername,
'Password'=>$strPassword
],
'Body'=>[
...
],
'Footer'=>[
'Hash'=>$strHash
]
]
];
$SoapClient = new SoapClient(<WSDL URL>);
$resp = $SoapClient->method($arrParameters);
Thank you IMSoP and axiac!
I have a small problem which I can't solve.
I'm trying to connect to a SOAP API (criteo) which works fine with SoapUI.
When I try to replicate the logic in e.g. php I get auth. errors.
I'm pretty sure that the header information are not passed correctly (I tried already several solutions which I found here without any result).
This is the request in SoapUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v20="https://advertising.criteo.com/API/v201010">
<soapenv:Header>
<v20:apiHeader>
<v20:authToken>12345</v20:authToken>
<v20:appToken>123456</v20:appToken>
</v20:apiHeader>
</soapenv:Header>
<soapenv:Body>
<v20:getReportDownloadUrl>
<v20:jobID>12345</v20:jobID>
</v20:getReportDownloadUrl>
</soapenv:Body>
</soapenv:Envelope>
In php I created the header like that:
/*
* wsdl: https://advertising.criteo.com/API/v201010/AdvertiserService.asmx?WSDL
*/
$authTokens = new stdClass();
$authTokens->authToken = 12345;
$authTokens->appToken = '123456';
$header = new SoapHeader('https://advertising.criteo.com/API/v201010/AdvertiserService.asmx', "apiHeader", $authTokens, true);
$client->__setSoapHeaders(array($header));
print_r($client->getAccount());
When I run the script I'll get an error:
Uncaught SoapFault exception: [soap:Receiver] Server was unable to process request. ---> Unable to cast object of type 'System.Web.Services.Protocols.SoapUnknownHeader' to type 'Criteo.WebService.DataModel.apiHeader'
Can somebody give me a hint ?
Thanks for the help.
Got the same problem. Change namespace value to https://advertising.criteo.com/API/v201010 from https://advertising.criteo.com/API/v201010/AdvertiserService.asmx
I have a page which will receive data directly from a SOAP request. The problem is "How will I receive that data?". If data is coming directly in $_GET parameter, I can fetch via $_GET['PARAM'], but how will I fetch data here as it is coming directly in SOAP?
I have a WSDL file, NotificationToCP.wsdl as well.
Following is the SOAP request.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sub="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<sub:handleNewSubscription>
<custAttributesDTO>
<cpId>{$cpId}</cpId>
<cpPwd>{$cpPwd}</cpPwd>
<productId>{$productId}</productId>
<channelName>{$channelName}</channelName>
<contentProvider>{$contentProvider}</contentProvider>
<cpName>{$cpName}</cpName>
<firstConfirmationDTTM>{$firstConfirmationDTTM}</firstConfirmationDTTM>
<secondConfirmationDTTM>{$secondConfirmationDTTM}</secondConfirmationDTTM>
</custAttributesDTO>
</sub:handleNewSubscription>
</soapenv:Body>
</soapenv:Envelope>
I am trying to fetch this SOAP request data with following code.
$client = new SoapClient($_SERVER['DOCUMENT_ROOT'] . "/test/NotificationToCP.wsdl", array('trace' => true));
var_dump($client->__getLastResponse());
I can't figure out where I am going wrong.
What you are returning from the SOAP call is an Object and you cannot print an Object you need to pull the value of the property of that object that stores your return value that you can then print. So in the SOAP XML where your response tag is, use the value of that tag and then:
print_r($result->name_Of_Tag_In_XML);
I'm having a problem in order to create a soap call. As one can see the header that is being supplied from a 3rd party client doesn't have a header name. I need to create a soap call by passing the username and password to the soap request which doesn't have a name in the header. I have tried several examples but no success. The call below works in soap UI but I'm having serious problems when it comes to php. Any help would be much appreciated
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://namespace.example.com/">
<soapenv:Header>
<int:password>123</int:password>
<int:login>abc</int:login>
</soapenv:Header>
<soapenv:Body>
<int:getEventTree>
<!--Optional:-->
<lang>en</lang>
</int:getEventTree>
</soapenv:Body>
</soapenv:Envelope>
Please take a look at http://php.net/manual/en/soapclient.dorequest.php
You can use code like:
$response = $soapClient->__doRequest(
$request,
$endpoint,
$soapAction,
$soapVersion,
$one_way
);
$request could be defined as a string containing xml, such as:
$request =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/""xmlns:int="http://namespace.example.com/">
<soapenv:Header>
<int:password>123</int:password>
<int:login>abc</int:login>
</soapenv:Header>
<soapenv:Body>
<int:getEventTree>
<!--Optional:-->
<lang>en</lang>
</int:getEventTree>
</soapenv:Body>
</soapenv:Envelope>';
You can define the rest of the arguments in the __doRequest() call depending on your configuration.
I am using Zend_Soap_Client to query data from a webservice provided by SAP. Since the auto-generated WSDL file has a few flaws, I use the non-WSDL mode of the client.
I managed to successfully call a webservice which only requires simple parameters, like strings. Example:
This is what SAP expects:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Header/>
<soapenv:Body>
<urn:Ze12RfcGetCustHistoryNew>
<PiDateHigh>2011-12-31</PiDateHigh>
<PiDateLow>1970-01-01</PiDateLow>
<PiKunnr>1</PiKunnr>
</urn:Ze12RfcGetCustHistoryNew>
</soapenv:Body>
</soapenv:Envelope>
This is my (working) code in PHP (with $soapClient already initialized in non-WSDL mode):
$soapClient->Ze12RfcGetCustHistoryNew(
new SoapParam(date('Y-m-d'), 'PiDateHigh'),
new SoapParam('1970-01-01', 'PiDateLow'),
new SoapParam('1', 'PiKunnr')
);
But as soon as I have to pass more complex parameters to the service, it does not work. Again, an example:
This is what SAP expects:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soapenv:Header/>
<soapenv:Body>
<urn:Ze12RfcGetCustHistoryNew>
<PiDateHigh>2011-12-31</PiDateHigh>
<PiDateLow>1970-01-01</PiDateLow>
<PiKunnr>1</PiKunnr>
<PiTBelegart>
<item>
<BelegartTyp>FAKTURA</BelegartTyp>
<Belegart>ZF2</Belegart>
</item>
</PiTBelegart>
</urn:Ze12RfcGetCustHistoryNew>
</soapenv:Body>
</soapenv:Envelope>
I have tried to use a multi-dimensional array containing SoapParams, but that did not work. In WSDL mode, I could pass the params as an array, without the need of using SoapParams. How can I do this in non-WSDL mode?
just a "quick-hit" ... I'm working in a different environment, but initially had my soap-value troubles too.
One solution for a particular problem was to pass complex arrays this way:
$data = (object)$complexArray;
$result = $webserviceClient->getResult($data);
"Casting" to object results in a StdClass object ... which often works fine for webservices.
Good Luck!
I have not come up with a nice solution for this yet - currently I pass the parameters to the client object as raw xml. That works, but does not seem to be the best way to do this. This is my code now:
$params = '
<PiDateHigh>2011-12-31</PiDateHigh>
<PiDateLow>1970-01-01</PiDateLow>
<PiKunnr>1</PiKunnr>
<PiTBelegart>
<item>
<BelegartTyp>FAKTURA</BelegartTyp>
<Belegart>ZF2</Belegart>
</item>
</PiTBelegart>
';
$result = $this->_client->Ze12RfcGetCustHistoryNew(new SoapVar($params,XSD_ANYXML));