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>
Related
Weird situation using SoapClient
I have the following code to fire a simple soap request.
$client = new \SoapClient($this->wsdlURI, [
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => 'SOAP_1_2',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS|SOAP_USE_XSI_ARRAY_TYPE
]);
$request = [
'dataRequest' => [
'UserId' => '***',
'AccountNumber' => (string) $customer->getAccountNumber(),
'PremiseAddress' => [
'ZipCode' => (string) $customer->getZip()
]
]
];
try {
$return = $client->searchAccounts($request);
} catch (\SoapFault $fault) {
...
}
I would expect the request to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://com/dom/ec/services" xmlns:java="java:com.dom.ec.beans">
<soapenv:Header/>
<soapenv:Body>
<ser:searchAccounts>
<ser:dataRequest>
<java:UserId>***</java:UserId>
<java:AccountNumber>00000000</java:AccountNumber>
<java:PremiseAddress>
<java:ZipCode>00000</java:ZipCode>
</java:PremiseAddress>
</ser:dataRequest>
</ser:searchAccounts>
</soapenv:Body>
</soapenv:Envelope>
It instead or formatted like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://cso.dom.com/ecservices/">
<SOAP-ENV:Body>
<ns1:SearchAccounts>
<ns1:dataRequest>
<item>
<key>UserId</key>
<value>***</value>
</item>
<item>
<key>AccountNumber</key>
<value>0000000000</value>
</item>
<item>
<key>PremiseAddress</key>
<value>
<item>
<key>ZipCode</key>
<value>00000</value>
</item>
</value>
</item>
</ns1:dataRequest>
</ns1:SearchAccounts>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Is there an option I am missing?
What I realized I was missing was the judicious use of SoapVar as well using StdClass rather than associative arrays.
Final code looked like this:
$client = new \SoapClient($this->wsdlURI, [
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => 'SOAP_1_2',
'features' => SOAP_SINGLE_ELEMENT_ARRAYS|SOAP_USE_XSI_ARRAY_TYPE
]);
$premiseAddress = new \stdClass();
$premiseAddress->ZipCode = (string) $customer->getZip();
$dataRequest = new \stdClass();
$dataRequest->AccountNumber = (string) $customer->getAccountNumber();
$dataRequest->CompanyNumber = '04';
$dataRequest->UserId = 'EFI';
$dataRequest->PremiseAddress = new \SoapVar($premiseAddress, SOAP_ENC_OBJECT);
$searchRequest = new \stdClass();
$searchRequest->dataRequest = new \SoapVar($dataRequest, SOAP_ENC_OBJECT);
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>
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')));
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'));
I'm trying to make a soap request and having difficulties.
Here is my php:
<?php
$option=array('trace'=>1);
$soapClient = new SoapClient('http://www.domain.com/ws/AccountManagement.wsdl', $option);
$headers = array('LOGIN_ID' => 'user#user.com', 'LOGIN_PASSWORD' => 'mypassword');
$header = new SoapHeader('https://www.domain.com', 'AuthenticationDTO', $headers, false);
$soapClient->__setSoapHeaders($header); //or array($header)
$params = array(
'bureauName' => '',
'businessInformation' => array('address' => array('city' => 'SomeCity'), array('country' => 'US'), array('state' => 'MN'), array('street' => 'Some Address'), array('zipCode' => '33212')), array('businessName' => 'SomeBusinessName'),
'entityType' => '',
'listOfSimilars' => 'true',
);
try {
$result = $soapClient->__call("matchCompany", $params);
print_r($result);
} catch (SoapFault $fault) {
echo $fault->faultcode . "-" . $fault->faultstring;
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}
?>
It fails on $soapClient__call.
getLastRequest() produces this XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com.dnbi.eai.service.AccountSEI" xmlns:ns2="http://dto.eai.dnbi.com">
<SOAP-ENV:Header>
<ns2:AuthenticationDTO>
<ns2:LOGIN_ID>user#user.com</ns2:LOGIN_ID>
<ns2:LOGIN_PASSWORD>mypassword</ns2:LOGIN_PASSWORD>
</ns2:AuthenticationDTO>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:matchCompany/>
<param1><item>
<key>address</key>
<value><item>
<key>city</key>
<value>SomeCity</value>
</item></value>
</item><item>
<key>0</key>
<value><item>
<key>country</key>
<value>US</value>
</item></value>
</item><item>
<key>1</key>
<value><item>
<key>state</key>
<value>MN</value>
</item></value>
</item><item>
<key>2</key>
<value><item>
<key>street</key>
<value>Some Address</value>
</item></value>
</item><item>
<key>3</key>
<value><item>
<key>zipCode</key>
<value>33212</value>
</item></value>
</item></param1>
<param2><item>
<key>businessName</key>
<value>SomeBusinessName</value>
</item></param2>
<param3></param3>
<param4>true</param4>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is not the correct XML output. I must be doing something wrong. Using soapUI I found that this is the correct XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dto="http://dto.eai.dnbi.com" xmlns:com="http://com.dnbi.eai.service.AccountSEI">
<soapenv:Header>
<dto:AuthenticationDTO>
<dto:LOGIN_ID>user#user.com</dto:LOGIN_ID>
<dto:LOGIN_PASSWORD>mypassword</dto:LOGIN_PASSWORD>
</dto:AuthenticationDTO>
</soapenv:Header>
<soapenv:Body>
<com:matchCompany>
<com:in0>
<!--Optional:-->
<dto:bureauName></dto:bureauName>
<!--Optional:-->
<dto:businessInformation>
<dto:address>
<!--Optional:-->
<dto:city>SomeCity</dto:city>
<dto:country>US</dto:country>
<dto:state>MN</dto:state>
<dto:street>Some Address</dto:street>
<!--Optional:-->
<dto:zipCode></dto:zipCode>
</dto:address>
<!--Optional:-->
<dto:businessName>SomeBusinessName</dto:businessName>
</dto:businessInformation>
<!--Optional:-->
<dto:entityNumber></dto:entityNumber>
<!--Optional:-->
<dto:entityType></dto:entityType>
<!--Optional:-->
<dto:listOfSimilars>true</dto:listOfSimilars>
</com:in0>
</com:matchCompany>
</soapenv:Body>
</soapenv:Envelope>
Can anybody help me produce the same XML that soapUI produced for me, but using PHP5's native Soap client?
Thanks
Try this code instead. Note how it uses anonymous objects to create the required hierarchy:
$options = array(
'trace' => 1
);
$soapClient = new SoapClient('http://www.domain.com/ws/AccountManagement.wsdl', $option);
$headers = array(
'LOGIN_ID' => 'user#user.com',
'LOGIN_PASSWORD' => 'mypassword'
);
$header = new SoapHeader('dto', 'AuthenticationDTO', $headers, false);
$soapClient->__setSoapHeaders($header);
$matchCompany->in0->bureauName = '';
$matchCompany->in0->businessInformation->address->city = 'SomeCity';
$matchCompany->in0->businessInformation->address->country = 'US';
$matchCompany->in0->businessInformation->address->state = 'MN';
$matchCompany->in0->businessInformation->address->street = 'Some Address';
$matchCompany->in0->businessInformation->address->zipCode = '33212';
$matchCompany->in0->businessInformation->businessName = 'SomeBusinessName';
$matchCompany->in0->entityType = '';
$matchCompany->in0->listOfSimilars = true;
try
{
$result = $soapClient->matchCompany($matchCompany);
print_r($result);
}
catch(SoapFault $fault)
{
echo $fault->faultcode . "-" . $fault->faultstring;
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}