SOAP HEADERS error - php

I'm having some problems by making my SOAP headers:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="elementos" xmlns:ns2="elementoscomunes">
<SOAP-ENV:Header>
<ns2:CABECERA>
<item>
<key>Element</key>
<value>
<item>
<key>Key</key>
<value/>
</item>
<item>
<key>Values</key>
<value>
<item>
<key>Value</key>
<value/>
</item>
</value>
</item>
</value>
</item>
</ns2:CABECERA>
So, ITEM tags are added because the namespace must not be found, i've tried to change the namespace root, but i think this is not the solution..
My service is under ssl, does all namespaces must be under ssl?
Can the tag be the error code explanation?
A PHP Error was encountered
Severity: Warning
Message: SoapClient::__doRequest(): SSL: Connection reset by peer
AND
THE SOAP FAULT:
SoapFault Object
(
[message:protected] => Error Fetching http headers
My original .wdsl has the next header definition:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:elem="elementoscomunes" xmlns:elem1="elementos">
<soapenv:Header>
<elem:CABECERA>
<!--Zero or more repetitions:-->
<Element>
<Key>?</Key>
<Values>
<!--Zero or more repetitions:-->
<Value>?</Value>
</Values>
</Element>
</elem:CABECERA>
</soapenv:Header>
</elem:CABECERA>
</soapenv:Header>
Does i have to add a new namespace?
I'm on an Apache Server so key tag must be "Key" i generate the code as shown below:
$headerbody = array('Element' => array('Key' => '', 'Values' => array('Value' => '')));
$header = new SOAPHeader('namespace', 'CABECERA', $headerbody );
$sClient->__setSoapHeaders($header);
Any Suggestions?
Thanks you!

I think it's too old, but my solution to do this was:
just replace this:
$headerbody = array('Element' => array('Key' => '', 'Values' => array('Value' => '')));
with this:
$headerbody = (object) array('Element' => array('Key' => '', 'Values' => array('Value' => '')));
Hope this help.!

When using php soap client sending data to the header or the body will result in the addition of item tags if the data is an array.
i.e.
$this->header(NAMESPACE, 'abc', [
'animal' => 'dog,
]);
becomes
<SOAP-ENV:Header>
<ns1:abc>
<item>
<key>animal</key>
<value>dog</value>
</item>
</ns1:abc>
</SOAP-ENV:Header>
Sending an object
$this->header(NAMESPACE, 'abc', (object)[
'animal' => 'dog,
]);
becomes
<SOAP-ENV:Header>
<ns1:abc>
<animal>dog</animal>
</ns1:abc>
</SOAP-ENV:Header>

Related

PHP - Array to XML with CDATA

I need to create an xml to send via soap, but I can not. I need an xml with a CDATA tag and I can not do it.
The xml must be in this format:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="url-here">
<soapenv:Header/>
<soapenv:Body>
<ser:callServiceMethod>
<!--Optional:-->
<xml>
<![CDATA[<fruits>
<type>G</type>
<flav>grape</flav>
<orders>
<order>
<client>12345</client>
<itens>
<item>
<cod>1</cod>
<name>Grape</name>
</item>
<item>
<cod>2</cod>
<name>Apple</name>
</item>
</itens>
</order>
</orders>
</fruits>]]>
</xml>
</ser:callServiceMethod>
</soapenv:Body>
</soapenv:Envelope>
I tried to create an array to generate the xml, this works, but without the CDATA, like this:
$soapArgs = array(
'xml' => array(
//need CDATA here
'fruits' => array(
'type' => 'G',
'flav' => 'grape',
'orders' => array(
'order' => array(
'client' => 12345,
'itens' => array(
'item' => array(
'cod' => 1,
'name' => 'Grape',
),
'item' => array(
'cod' => 2,
'name' => 'Apple',
),
)
)
)
)
)
);
$soapClient = new SoapClient($params);
$serviceResponse = $soapClient->callServiceMethod($soapArgs);
How do I generate this xml with CDATA to be able to send via SOAP?
Thank you guys!
As discussed under What does <![CDATA[]]> in XML mean? a CDATA section is a way of including a string in an XML document without it being parsed. Everything from <fruits> to </fruits> is therefore not part of the actual XML document; as far as the SOAP request is concerned, it's just a string.
(This kind of thing is quite common in SOAP services, because people find it easier to parse the payload outside of their SOAP code, so they use SOAP as a large wrapper around arbitrary content. It could just as well be <json><![CDATA[{"foo": "bar"}]]></json> or some other format of payload.)
Assuming the owner of the SOAP service hasn't done something really weird, this:
<xml>
<![CDATA[<fruits>
<type>G</type>
<flav>grape</flav>
<orders>
<order>
<client>12345</client>
<itens>
<item>
<cod>1</cod>
<name>Grape</name>
</item>
<item>
<cod>2</cod>
<name>Apple</name>
</item>
</itens>
</order>
</orders>
</fruits>]]>
</xml>
should be completely equivalent to this:
<xml>
<fruits>
<type>G</type>
<flav>grape</flav>
<orders>
<order>
<client>12345</client>
<itens>
<item>
<cod>1</cod>
<name>Grape</name>
</item>
<item>
<cod>2</cod>
<name>Apple</name>
</item>
</itens>
</order>
</orders>
</fruits>
</xml>
The function creating the XML will handle escaping the string, or wrapping it in CDATA, so all you should need is:
$xml = '<fruits>
<type>G</type>
<flav>grape</flav>
<orders>
<order>
<client>12345</client>
<itens>
<item>
<cod>1</cod>
<name>Grape</name>
</item>
<item>
<cod>2</cod>
<name>Apple</name>
</item>
</itens>
</order>
</orders>
</fruits>';
$soapArgs = array('xml' => $xml);
How you create the string $xml is, obviously, up to you.

How to use namespaces in SOAP client xml request

I'm new to using SOAP and PHP, and I need to create a request exactly like this using PHP SoapClient class:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ent="http://enterprise.000.000.com/Infrastructure/EnterpriseContext"
xmlns:ns="http://000.000.com/000/service/000/intf/1">
<soap:Header>
<ent:enterpriseContext>
<ent:contextInfo>
<ent:ProcessContextId>000K121300223393915419638486638404</ent:ProcessContextId>
<ent:businessContextId>CO</ent:businessContextId>
<ent:applicationContextId>3</ent:applicationContextId>
</ent:contextInfo>
<ent:requestOriginator>
<ent:requesterCode>000</ent:requesterCode>
<ent:machineIPAddress>0.0.0.0</ent:machineIPAddress>
<ent:userPrincipleName>000</ent:userPrincipleName>
<ent:requestedTimestamp>2015-10-01T05:53:04</ent:requestedTimestamp>
<ent:channelId>1</ent:channelId>
</ent:requestOriginator>
</ent:enterpriseContext>
</soap:Header>
<soap:Body>
<ns:InitiatePaymentDetails>
<InitiatePaymentDetailsRequest>
<transactionAmount>35</transactionAmount>
<olpIdAlias>000_uat_uat1</olpIdAlias>
<merchantRefNum>7999</merchantRefNum>
<!--1 or more repetitions:-->
<merchants>
<merchantId>1003</merchantId>
<merchantRefNum>7999</merchantRefNum>
<paymentAmount>35</paymentAmount>
<paymentCurrency>SAR</paymentCurrency>
<merchantType>1</merchantType>
</merchants>
<merchantId>1003</merchantId>
</InitiatePaymentDetailsRequest>
</ns:InitiatePaymentDetails>
</soap:Body>
</soap:Envelope>
How can I achieve that?
I just managed to solve the problem
Although the code I used didn't produce an identical XML request, but It fulfills the web service requirements. I put the answer here for any one with a similar problem.
$wsdl = 'https://000.000.com/000abpayproc-ws/000PaymentManager.wsdl';
$client = new SoapClient($wsdl, array('trace' => 1));
$unique_id = mt_rand(100000, 999999);
$timestamp = time();
$ref_number = mt_rand(10000000, 99999999);
$headerbody = array(
'contextInfo' => array(
'ProcessContextId' => '000'.$unique_id.$timestamp,
'businessContextId' => 'CO',
'applicationContextId' => 3
),
'requestOriginator' => array(
'requesterCode' => '000',
'machineIPAddress' => '00.00.00.00',
'userPrincipleName' => '000',
'requestedTimestamp' => '2015-10-01T05:53:04',
'channelId' => 1
),
);
$ns = 'http://000.000.com/000/service/000/intf/1';
$header = new SOAPHeader($ns, 'enterpriseContext', $headerbody);
$ent = 'http://000.000.000.com/Infrastructure/EnterpriseContext';
$header2 = new SOAPHeader($ent, 'enterpriseContext', $headerbody);
$parm = array(
'InitiatePaymentDetailsRequest' =>
array(
'transactionAmount' => 35,
'olpIdAlias' => '000',
'merchantRefNum' => $ref_number,
'merchants' => array(
'merchantId' => 1003,
'merchantRefNum' => 7999,
'paymentAmount' => 35,
'paymentCurrency' => 'SAR',
'merchantType' => 1,
),
'merchantId' => 1003
)
);
try {
$resp = $client->__soapCall('InitiatePaymentDetails', array($parm), array(), array($header, $header2));
echo 'REQUEST:<br />';
var_dump($client->__getLastRequest());
echo '<br />';
echo 'RESPONSE:<br />';
dd($resp);
} catch (SoapFault $ex) {
echo 'REQUEST:<br />';
$client->__getLastRequest();
echo '<br />';
echo 'RESPONSE:<br />';
echo $ex->getMessage();
}
The resulting request was as follows:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://000.000.com/000/service/000/intf/1" xmlns:ns2="http://enterprise.000.000.com/Infrastructure/EnterpriseContext">
<SOAP-ENV:Header>
<ns1:enterpriseContext>
<item>
<key>contextInfo</key>
<value>
<item>
<key>ProcessContextId</key>
<value>0004331921464611756</value>
</item>
<item>
<key>businessContextId</key>
<value>CO</value>
</item>
<item>
<key>applicationContextId</key>
<value>3</value>
</item>
</value>
</item>
<item>
<key>requestOriginator</key>
<value>
<item>
<key>requesterCode</key>
<value>000</value>
</item>
<item>
<key>machineIPAddress</key>
<value>00.00.00.00</value>
</item>
<item>
<key>userPrincipleName</key>
<value>000</value>
</item>
<item>
<key>requestedTimestamp</key>
<value>2015-10-01T05:53:04</value>
</item>
<item>
<key>channelId</key>
<value>1</value>
</item>
</value>
</item>
</ns1:enterpriseContext>
<ns2:enterpriseContext>
<ns2:contextInfo>
<ns2:ProcessContextId>004331921464611756</ns2:ProcessContextId>
<ns2:businessContextId>CO</ns2:businessContextId>
<ns2:applicationContextId>3</ns2:applicationContextId>
</ns2:contextInfo>
<ns2:requestOriginator>
<ns2:requesterCode>000</ns2:requesterCode>
<ns2:machineIPAddress>00.00.00.00</ns2:machineIPAddress>
<ns2:userPrincipleName>000</ns2:userPrincipleName>
<ns2:requestedTimestamp>2015-10-01T05:53:04</ns2:requestedTimestamp>
<ns2:channelId>1</ns2:channelId>
</ns2:requestOriginator>
</ns2:enterpriseContext>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:InitiatePaymentDetails>
<InitiatePaymentDetailsRequest>
<transactionAmount>35</transactionAmount>
<olpIdAlias>000</olpIdAlias>
<merchantRefNum>51777161</merchantRefNum>
<merchants>
<merchantId>1003</merchantId>
<merchantRefNum>7999</merchantRefNum>
<paymentAmount>35</paymentAmount>
<paymentCurrency>SAR</paymentCurrency>
<merchantType>1</merchantType>
</merchants>
<merchantId>1003</merchantId>
</InitiatePaymentDetailsRequest>
</ns1:InitiatePaymentDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP Request Header is not well-formatted (Contains <item>, <key> and <value>)

The header of my SOAP Request is displayed in a weird format. I need to have a header that looks like this:
<soap-env:header>
<wsse:security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:usernametoken wsu:id="UsernameToken-45">
<wsse:username>817221</wsse:username>
<wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234</wsse:password>
</wsse:usernametoken>
</wsse:security>
</soap-env:header>
Right now, the header looks like this:
<SOAP-ENV:Header>
<ns8:Security SOAP-ENV:mustUnderstand="1">
<item>
<key>UsernameToken</key>
<value>
<item>
<key>Username</key>
<value>817221</value>
</item>
<item>
<key>Password</key>
<value>
<item>
<key>_</key>
<value>1234</value>
</item>
<item>
<key>Type</key>
<value>http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText</value>
</item>
</value>
</item>
</value>
</item>
</ns8:Security>
</SOAP-ENV:Header>
It's so wrong. It contains and tags. I've read that SOAP_ENC_OBJECT should be used to display it in correct format so I tried it in my code but still doesn't work. See the code below:
$header = array(
'UsernameToken' => array(
'Username' => 817221,
'Password' => array(
'_' => 1234,
'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')));
$headerSoapVar = new SoapVar($header,SOAP_ENC_OBJECT);
$soapheader = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', "Security" , $header, true);
$client->__setSoapHeaders($soapheader);
Any help would be greatly appreciated. Thanks!
This is quite an old question!
However, I had this very same problem today!
I found out that "header" needs to be an object, not an array!
However I still had problems with namespaces... so I worked it out Sub-classing SoapClient class
class MySoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way=0) {
// manipulate $request var using XML parse tools or whatever !!
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
I am still working this out, but I hope it helps somebody !
Try this you should set it as an object.
$header = (object) array(
'UsernameToken' => array(
'Username' => 817221,
'Password' => array(
'_' => 1234,
'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')));

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

Creating a SOAP call using PHP with an XML body

I'm trying to call a SOAP method using PHP.
Here's the code I've got:
$data = array('Acquirer' =>
array(
'Id' => 'MyId',
'UserId' => 'MyUserId',
'Password' => 'MyPassword'
));
$method = 'Echo';
$client = new SoapClient(NULL,
array('location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
'uri' => 'http://example.com/wsdl', 'trace' => 1));
$result = $client->$method($data);
Here's the request it creates:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/wsdl" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:Echo>
<param0 xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">Acquirer</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">Id</key>
<value xsi:type="xsd:string">mcp</value>
</item>
<item>
<key xsi:type="xsd:string">UserId</key>
<value xsi:type="xsd:string">tst001</value>
</item>
<item>
<key xsi:type="xsd:string">Password</key>
<value xsi:type="xsd:string">test</value>
</item>
</value>
</item>
</param0>
</ns1:Echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here's what I want the request to look like:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/wsdl" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<Echo>
<Acquirer>
<Id>MyId</Id>
<UserId>MyUserId</UserId>
<Password>MyPassword</Password>
</Acquirer>
</Echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
There are a couple of ways to solve this. The least hackiest and almost what you want:
$client = new SoapClient(
null,
array(
'location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
'uri' => 'http://example.com/wsdl',
'trace' => 1,
'use' => SOAP_LITERAL,
)
);
$params = new \SoapVar("<Acquirer><Id>MyId</Id><UserId>MyUserId</UserId><Password>MyPassword</Password></Acquirer>", XSD_ANYXML);
$result = $client->Echo($params);
This gets you the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/wsdl">
<SOAP-ENV:Body>
<ns1:Echo>
<Acquirer>
<Id>MyId</Id>
<UserId>MyUserId</UserId>
<Password>MyPassword</Password>
</Acquirer>
</ns1:Echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
That is almost exactly what you want, except for the namespace on the method name. I don't know if this is a problem. If so, you can hack it even further. You could put the <Echo> tag in the XML string by hand and have the SoapClient not set the method by adding 'style' => SOAP_DOCUMENT, to the options array like this:
$client = new SoapClient(
null,
array(
'location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
'uri' => 'http://example.com/wsdl',
'trace' => 1,
'use' => SOAP_LITERAL,
'style' => SOAP_DOCUMENT,
)
);
$params = new \SoapVar("<Echo><Acquirer><Id>MyId</Id><UserId>MyUserId</UserId><Password>MyPassword</Password></Acquirer></Echo>", XSD_ANYXML);
$result = $client->MethodNameIsIgnored($params);
This results in the following request XML:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<Echo>
<Acquirer>
<Id>MyId</Id>
<UserId>MyUserId</UserId>
<Password>MyPassword</Password>
</Acquirer>
</Echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Finally, if you want to play around with SoapVar and SoapParam objects, you can find a good reference in this comment in the PHP manual: http://www.php.net/manual/en/soapvar.soapvar.php#104065. If you get that to work, please let me know, I failed miserably.
First off, you have to specify you wish to use Document Literal style:
$client = new SoapClient(NULL, array(
'location' => 'https://example.com/path/to/service',
'uri' => 'http://example.com/wsdl',
'trace' => 1,
'use' => SOAP_LITERAL)
);
Then, you need to transform your data into a SoapVar; I've written a simple transform function:
function soapify(array $data)
{
foreach ($data as &$value) {
if (is_array($value)) {
$value = soapify($value);
}
}
return new SoapVar($data, SOAP_ENC_OBJECT);
}
Then, you apply this transform function onto your data:
$data = soapify(array(
'Acquirer' => array(
'Id' => 'MyId',
'UserId' => 'MyUserId',
'Password' => 'MyPassword',
),
));
Finally, you call the service passing the Data parameter:
$method = 'Echo';
$result = $client->$method(new SoapParam($data, 'Data'));

Categories