Fetch PHP SOAP request data - php

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

Related

How can I format a PHP array that uses elements and attributes?

I am trying to send a SOAP request via PHP and while I am able to send via SOAPUI, I am having an issue formatting in PHP. The schema, located here shows an attribute embedded in the routePartitionName element which is where my code is falling apart. I need to send the pattern and routePartitionName in my array. Here is part of the SOAP request that is working:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/12.5">
<soapenv:Header/>
<soapenv:Body>
<ns:getLine sequence="?">
<pattern>6304389152</pattern>
<routePartitionName uuid="{BE888889-7C30-4C89-0CC4 C99FDE1025A9}">NA_DID_XLATE_PT</routePartitionName>
<returnedTags uuid="?">
.....
.....
</returnedTags>
Here is what I am sending in PHP that does not work:
$lineinfo = array("routePartitionName"=>"uuid={BE888889-7C30-4C89-0CC4-C99FDE1025A9}",
"pattern"=>"6304389152");
The logs show `[soapenv:Server] Item not valid: The specified uuid={BE888889-7C30-4C89-0CC4-C99FDE1025A9} was not found `
Can someone let me know what I am missing here?
Thanks.

SOAP request and repsonse with PHP (display response)

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

PHP API Soap Header Authentication

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

returning soap xml response for a soap server php

I am trying to create a soap service in php using native php soap server. I have already prepared the wsdl file.
There are basically four methods that can be called with the soap service. The input soap request for one of the request ShowRemittanceDetail is shown below.
<soap-env:body>
<ns1:showremittancedetailrequest>
<username>admin</username>
<password>pass</password>
<refno>USA1956127848</refno>
</ns1:showremittancedetailrequest>
</soap-env:body>
Anyway the soap request does not have a header and I have just shown the body here. I have no problem parsing the soap request. The response should look like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<ns2:responseType xmlns:ns2="http://tempuri.org/response">
<code>00</code>
<message>Transaction does not exist or is not available</message>
<responseBody>
<responseStr>4</responseStr>
</responseBody>
</ns2:responseType>
</soapenv:Body>
</soapenv:Envelope>
This is a particular response which is generated when the transaction with the reference number is not available in the server.
I have received the soap request and evaluated it. However I have a problem with the return type of the soap response. I cannot generate a valid response. What type of response should a soap server return?
Things I have tried:
I have tried returning an xml string. But the soap client request throws an exception with the following message.
looks like we got no xml document.
I have also tried returing a native php SoapVar() with the same result.
I have tried returning an object response that is specified in the classmap fo the soap server.
e.g. for the example above, I have tried returning a ShowRemittanceDetailResponse object with the same result. (looks like we got no xml document).
I have tried returning a DomDocument Object . The exception thrown in this case is
the encoded object does not have a responseStr property.
I have tried returning an stdClass object with the same fields as the response expects with similar result.
Please help me.
Thanks in advance.
The solution I found was returning a SoapVar object. I didnt have soapui and the client I wrote in php was incorrect. Hence, I had problem verifying the returned xml as the php soap client was throwing an exception. The correct way for me was to return a SoapVar.

Passing Arrays as Parameters to Soap Webservice in non-WSDL mode

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

Categories