I'm at a slight loss, havent touched a soap script in forever and looking around stackoverflow and google just confuses the matter more. PHP.net examples seem outdated as well.
The SOAP Request is supposed to POST to a non-WSDL url.
https://some.soapurl.com/provided
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>
Just running this snippet returns a 200 OK header, which is good.
try {
$client = new SoapClient("https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated");
}
catch(Exception $e)
{
$e->getMessage();
}
The Response i'm looking to get is supposed to look like
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:returnStatus xmlns:ns1="http://kamp.gw.com/kamp">
<ns1:type>S</ns1:type>
<ns1:desc>Successful</ns1:desc>
</ns1:returnStatus>
</soapenv:Body>
</soapenv:Envelope>
EDIT:
I attempted a curl version to post the xml string directly.
$post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cam="http://kamp.gw.com/kamp">
<soapenv:Header/>
<soapenv:Body>
<cam:setRolesUpdatedRequest>
<cam:orgCode>username</cam:orgCode>
<cam:password>password</cam:password>
<cam:emails>
<cam:email>abc#dom.com</cam:email>
<cam:email>def#dom.com</cam:email>
<cam:email>ghi#dom.com</cam:email>
</cam:emails>
<cam:updateAllUsers>false</cam:updateAllUsers>
</cam:setRolesUpdatedRequest>
</soapenv:Body>
</soapenv:Envelope>';
$user = "username";
$password = "password";
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
"Content-length: ".strlen($xml),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://abc.kamp.group.com/axis/services/KampService/setRolesUpdated" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 100000);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers); //array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) )
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
var_dump($result);
echo "<br /><br />";
var_dump($err);
But unfortunately the result is
bool(false)
string(74) "Failed connect to abc.kamp.group.com:443; Connection timed out"
And i'm not certain if that's my fault or the web service's fault. Even though i get connection timed out, the header returned is still 200 Ok.
First check that the SOAP service url and access credentials are working. Use SoapUI or a similar tool to make a request independent of your PHP SoapClient code.
Also check if there are any IP address restrictions in place when making calls and, if so, create / ask for an exception for the IP address you are making requests from.
If everything checks, use php.net SoapClient examples to make simple calls and build your script logic.
<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>
Forgot i was behind a proxy, once i pointed curl to the proxy server everything worked out just fine.
Related
I was trying to hit XML request from PHP SOAP Client according to the following provided SOAP API documentation.
WSDL Schema
Refer to the following URL.
http://[SERVER_IP]/PowerSuite/PSXMLSearch.asmx?wsdl
4 Input/Output
4.1 Search Supplier Code and Name (PSXMLSearchSupplier)
Input : PSXML_SEARCH_SUPP
Output : PSXML_SEARCH_SUPP_Response
6 Field definition
6.1 PSXML_SEARCH_SUPP - The main entry point and the authentication information.
MSGID
USERID
PASSWORD
OPTION
SUPPNO
But when i run with SOAP client it gives me a following error
Object reference not set to an instance of an object
So after long research on internet, i decided to send XML request via CURL, i have created following Schema for XML request and send it via CURL request
$soapUrl = "https://[MY_SERVER_DOMAIN]/PowerSuite/PSXMLSearch.asmx"; // asmx URL of WSDL
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PSXML_SEARCH_SUPP xmlns="https://[MY_SERVER_DOMAIN]/PowerSuite/PSXMLSearch.asmx">
<MSGID>TRAVEK_E1</MSGID>
<USERID>GCOT</USERID>
<PASSWORD>CKHOSKIS6</PASSWORD>
<OPTION>LIKE</OPTION>
<SUPPNO>RK0048</SUPPNO>
</PSXML_SEARCH_SUPP>
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"https://[MY_SERVER_DOMAIN]/PowerSuite\"",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "GCONNECT:Connect#786");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
// user $parser to get your data out of XML response and to display it.
echo "<pre>";
print_r($parser);
echo "</pre>";
die();
But even after that i only get empty XML response as can see below
SimpleXMLElement Object
(
)
Please guide am i sending a correct XML schema, or their needs to be some thing amend into it?
I checked with RapidAPI, it shows the correct response, i have shown the request in the image below:
In FORM
https://gcdnb.pbrd.co/images/a9NdABt6rXQl.png
In XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xh="http://www.xmlhk.com/">
<soapenv:Header/>
<soapenv:Body>
<xh:PSXMLSearchSupplier>
<!--Optional:-->
<xh:PSXML_SEARCH_SUPP>
<!--Optional:-->
<xh:MSGID>TRAVEK_EBOOK001</xh:MSGID>
<!--Optional:-->
<xh:USERID>ABCUSER</xh:USERID>
<!--Optional:-->
<xh:PASSWORD>Connect#786</xh:PASSWORD>
<!--Optional:-->
<xh:OPTION>LIKE</xh:OPTION>
<!--Optional:-->
<xh:SUPPNO>ABDECS</xh:SUPPNO>
<!--Optional:-->
<xh:SUPPNAME>?</xh:SUPPNAME>
</xh:PSXML_SEARCH_SUPP>
</xh:PSXMLSearchSupplier>
</soapenv:Body>
</soapenv:Envelope>
I tried the same above with CURL request and got that working, i found that,following to be changed in my previous CURL request
, which on the raw tab in ReadyAPI
"SOAPAction: \"http://www.xmlhk.com/PSXMLSearchSupplier\"",
To work this with SOAP Client i just need to used multi dimensional array with $params['PSXML_SEARCH_SUPP'] shows below
$wsdl = "https://ps.gerrys.com.pk/PowerSuite/PSXMLSearch.asmx?WSDL";
$params['PSXML_SEARCH_SUPP'] = array(
'MSGID' => "TRAVEK_EBOOK001",
'USERID' => "GCONNECT",
'PASSWORD' => "Connect#786",
'OPTION' => 'LIKE',
'SUPPNO' => 'RK0048'
);
try {
$soap = new SoapClient($wsdl);
$data = $soap->PSXMLSearchSupplier($params);
echo "<pre>";
print_r($data);
echo "</pre>";
die();
}
catch(Exception $e) {
$e->getMessage();
var_dump($e->getMessage());
die();
}
I need to post to a client's URL (in case it matters the client is on a .Net platform) using SOAP and XML. The request needs to look something like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:XXX="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX" xmlns:XXX1="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.Admin"> <soap:Header/> <soap:Body>
<tem:SaveXXXStatus>
<!--Optional:-->
<tem:req>
<!--Optional:-->
<XXX:AWBNumber>69184678146</XXX:AWBNumber>
<!--Optional:-->
… etc. …
<!--Optional:-->
<XXX:pincode></XXX:pincode>
</tem:req>
<!--Optional:-->
<tem:profile>
<!--Optional:-->
<XXX1:Api_type>S</XXX1:Api_type>
<!--Optional:-->
<XXX1:Area></XXX1:Area>
<!--Optional:-->
<XXX1:LicenceKey>xxxxxxxxxxxxxxxxxxx</XXX1:LicenceKey>
<!--Optional:-->
<XXX1:LoginID>XXXYYY</XXX1:LoginID>
<!--Optional:-->
<XXX1:Version>1</XXX1:Version>
</tem:profile>
</tem:SaveXXXStatus> </soap:Body> </soap:Envelope>
I am using the following code:
$ch = curl_init();
//var_dump($ch);
curl_setopt($ch, CURLOPT_URL,"https://example.com?wsdl");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'tem:"http://tempuri.org/"',
'Content-Type: text/xml',
'XXX:"http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX"'
'XXX1:"http://schemas.datacontract.org/2004/07/XXXAPI.Entities.Admin"'
));
//curl_setopt($ch, CURLOPT_USERPWD, "XXXYYY:xxxxxxxxxxxxx"); //Probably not needed
curl_setopt($ch, CURLOPT_POST, 1);
$strRequest = "";
$strRequest .= "AWBNumber=69184678161";
… etc….
$strRequest .= "&pincode=";
$strRequest .= "&Api_type=S";
$strRequest .= "&Area=";
$strRequest .= "&LicenceKey=xxxxxxxx";
$strRequest .= "&LoginID=XXXYYY";
$strRequest .= "&Version=1";
curl_setopt($ch, CURLOPT_POSTFIELDS,$strRequest);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
var_dump($server_output);
This post shows that the header (envelope etc.) can simply be added to the POSTFIELDS string but I tried that and it didn't work. Besides it seems like such a hack!
Anyway, no combination is working - I am getting a zero length string as a result ($server_output). What is the right way to pass the headers and what else needs to be fixed here?
i also stuck in this few days ago... but tried this way and got results
$xml_post_string ='<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:XXX="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX" xmlns:XXX1="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.Admin"> <soap:Header/> <soap:Body>
<tem:SaveXXXStatus>
<!--Optional:-->
<tem:req>
<!--Optional:-->
<XXX:AWBNumber>69184678146</XXX:AWBNumber>
<!--Optional:-->
… etc. …
<!--Optional:-->
<XXX:pincode></XXX:pincode>
</tem:req>
<!--Optional:-->
<tem:profile>
<!--Optional:-->
<XXX1:Api_type>S</XXX1:Api_type>
<!--Optional:-->
<XXX1:Area></XXX1:Area>
<!--Optional:-->
<XXX1:LicenceKey>xxxxxxxxxxxxxxxxxxx</XXX1:LicenceKey>
<!--Optional:-->
<XXX1:LoginID>XXXYYY</XXX1:LoginID>
<!--Optional:-->
<XXX1:Version>1</XXX1:Version>
</tem:profile>
</tem:SaveXXXStatus> </soap:Body> </soap:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: url",
"Content-length: " . strlen($xml_post_string),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, 'yoururl');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
print_r($response);
As I mentioned in the comments already, it would be much easier using the build in PHP SoapClient class and objects as entities. Here 's a little example, how you could solve your issue.
The PHP Soap Client
PHP got its own build in SoapClient which works pretty fine. Have a look how to initialize the client for development.
try {
$client = new \SoapClient('https://example.com?wsdl', [
'cache_wsdl' )> WSDL_CACHE_NONE,
'exceptions' => true,
'trace' => true,
]);
} catch (\SoapFault $fault) {
echo "<pre>";
var_dump($fault->getMessage());
echo "</pre>";
if ($client) {
echo "<pre>";
var_dump($client->__getLastRequest(), $client->__getLastResponse());
echo "</pre>";
}
}
This is a simple init of the SoapClient class with development options. Setting the trace option to true enables the use of the clients internal functions __getLastRequest() and __getLastResponse(). So you can see, what the client has sent and what the response looks like, if there 's any. I 'm using this for checking the xml that the client has sent.
Simple entities as objects that can be used by soap
SOAP defines itself as complex and simple type definitions. You can see this, if you call the clients own __getTypes() function. There will be displayed a lot of structs and simple type definitions, which are stored in the given wsdl file or in xsd files mentioned in the wsdl file. With this informations we are able to build our own object. In this example I 'm using simple stdClass objects. In production manner, you should use computed own objects.
$req = new \stdClass();
$req->AWBNumber = new \SoapVar(
69184678146,
XSD_INT,
null,
null,
'AWBNumber',
'http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX'
);
$encodedReq = new \SoapVar($req, SOAP_ENC_OBJECT, null, null, 'req', 'http://tempuri.org/');
$saveXXXStatus = new \stdClass();
$saveXXXStatus->req = $encodedReq;
$encodedSaveXXXStatus = new \SoapVar($saveXXXStatus, SOAP_ENC_OBJECT, null, null, 'SaveXXXStatus, 'http://tempuri.org/');
// send the content with the soap client
$result = $client->SaveXXXStatus($encodedSaveXXXStatus);
Please keep in mind, that this is a short example which is incomplete and will lead to a soap fault. But what I 've done here? The req node in your xml is an object. You 'll find the definition of this object in the above metioned __getTypes() function output. In this example I 've compiled this object as a stdClass with the property AWBNumber. The AWBNumber itself is a SoapVar object. We use a soap var because of the namespaces, which are used by the soap client. After defining a property we encode the req object as a soap object, which is also a SoapVar instance.
After all we call the webservice method SaveXXXStatus with the encoded parameter.
The Last Request
If you send this example, the last request should look like:
<ns1:envelope xmlns:ns1="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns2="http://tempuri.org/"
xmlns:ns3="http://schemas.datacontract.org/2004/07/XXXAPI.Entities.XXX">
<ns1:body>
<ns2:SaveXXXStatus>
<ns2:req>
<ns3:AWBNumber>69184678146</ns3:AWBNumber>
</ns2:req>
</ns2:SaveXXXStatus>
</ns1:body>
</ns1:envelope>
As I said before, this is just an example. You have to code all the nodes as SoapVar objects and append it to parents and finally call the webservice method with the complete encoded data.
Simple as pie, hm?
I have been trying to figure out how to make a soap request using php/laravel. But from all the research on internet since two days now the only things that I can find are old rusty php codes to make soap requests non of them even worked:
Here is a snipped that I am trying to make it work so I have a general view of those soap requests but I only get errors not able to make a soapclient:
<?php
$aHTTP['http']['header'] = "User-Agent: PHP-SOAP/5.5.11\r\n";
$aHTTP['http']['header'].= "username: XXXXXXXXXXX\r\n"."password: XXXXX\r\n";
$context = stream_context_create($aHTTP);
$client=new SoapClient("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl",array('trace' => 1,"stream_context" => $context));
$result = $client::__getFunctions();
var_dump($result);
since it looks super hard to me to find any info about the soap with php any idea ?
This is a sample of a soap request I currently make to a payment provider via php using curl statements. Basically map the xml request you want to make in a string. The string will be sent in the curl post fields and the response returned.
$soapdata="<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tns='tns:ns'>
<soapenv:Header>
<tns:CheckOutHeader>
<MERCHANT_ID>$merchantid</MERCHANT_ID>
<PASSWORD>$password</PASSWORD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:CheckOutHeader>
</soapenv:Header>
<soapenv:Body>
<tns:processCheckOutRequest>
<MERCHANT_TRANSACTION_ID>$merchanttransactionid</MERCHANT_TRANSACTION_ID>
<REFERENCE_ID>$referenceid</REFERENCE_ID>
<AMOUNT>$amount</AMOUNT>
<MSISDN>$mobileno</MSISDN>
<!--Optional:-->
<ENC_PARAMS></ENC_PARAMS>
<CALL_BACK_URL>$callbackurl</CALL_BACK_URL>
<CALL_BACK_METHOD>$callbackmethod</CALL_BACK_METHOD>
<TIMESTAMP>$timestamp</TIMESTAMP>
</tns:processCheckOutRequest>
</soapenv:Body>
</soapenv:Envelope>";
//End Soap data
//We call the server for the first time
//end calling function
function makesoaprequest($url, $soapdata)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml', 'Authorization: Basic'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$soapdata");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Begin SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//End SSL
$response = curl_exec($ch);
return $response;
curl_close($ch);
}
I want to configure an api of soap with php, following the xml is used for the api, but its not responding, please help me to recover this problem
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<userName>username</userName>
<password>password</password>
<agentCode>code</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>
The below showing the php code I used to call xml. But I didnt get any response to my php code, but the xml is correct, I have asked to the provider they told me the xml is correct but my php code is not correct. I dont what I do to solve this problem :(
<?php
$soapUrl = "http://testapi.roombookpro.com/en/soap/index?wsdl"; // asmx URL of WSDL
$soapUser = "username"; // username
$soapPassword = "password"; // password
// xml post structure
$xml_post_string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fram="http://framework.zend.com">
<soapenv:Header/>
<soapenv:Body>
<fram:getCountries>
<securityInfo>
<!-- You may enter the following 4 items in any order -->
<userName>username</userName>
<password>password</password>
<agentCode>agentcode</agentCode>
<lang>en</lang>
</securityInfo>
</fram:getCountries>
</soapenv:Body>
</soapenv:Envelope>'; // data from the form, e.g. some ID number
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache"
"SOAPAction: http://testapi.roombookpro.com/en/soap/index#getCountries",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
// converting
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
// convertingc to XML
$parser = simplexml_load_string($response2);
var_dump($parser);
echo $parser;
// user $parser to get your data out of XML response and to display it.
?>
In your code,your request is pointing to wsdl link below,
http://testapi.roombookpro.com/en/soap/index?wsdl
and thats why you are not getting soap response rather you getting the definitions.
you should use the following soap url to get the soap response,
http://testapi.roombookpro.com/en/soap/index
EDIT:
and to get the XML response (as string):
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
to get as SimpleXMLElement Object :
$xml = simplexml_load_string($response);
foreach ($xml->xpath('//ns2:Soap_Model_SOAP_Location_Country') as $item)
{
print_r($item);
//to access individual elements
// echo $item->id ;
// echo $item ->code;
// echo $item->name;
// echo "\n";
}
which gives array of XML objects:
SimpleXMLElement Object
(
[id] => 252
[code] => ZW
[name] => Zimbabwe
)
Good Evening All,
I am been fighting an uphill battle try to post xml data to an https web service. I am new to PHP so I am trying to learn as I go. I have been able to post the xml data to the web services via soapUI but I cannot recreate to process thru PHP. If anyone who a PHP SOAP guru could explain to me what I am doing wrong that would be a great help. Below is the code snippet I am trying to post to the web service.
<?php
$user = "xxxxxx";
$password = "xxxxx";
$url = "https://esws.energystar.gov/DataServices/servlet/webservices?ver=1.1&wsdlxml";
$post_string = <<<EOT
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:roof="http://www.energystar.gov/schema/Roof_Products_2_x/" xmlns:core="http://www.energystar.gov/schema/core/">
<soapenv:Header/>
<soapenv:Body>
<roof:Roof_Products_submission>
<core:core_submission>
<core:Authentication_UserName>xxxxx</core:Authentication_UserName>
<core:Authentication_Password>xxxxxxx</core:Authentication_Password>
<core:Certification_Body_EPA_Issued_Organization_Id>xxxxxxx</core:Certification_Body_EPA_Issued_Organization_Id>
<core:Is_Test_Submission>Yes</core:Is_Test_Submission>
</core:core_submission>
<!--1 or more repetitions:-->
<roof:Roof_Products>
<core:core_product_data>
<core:ENERGY_STAR_Manufacturing_Partner>QPX Active Partner</core:ENERGY_STAR_Manufacturing_Partner>
<core:ENERGY_STAR_Manufacturing_Partner_s_EPA_issued_Organization_ID>xxxxxxxxx</core:ENERGY_STAR_Manufacturing_Partner_s_EPA_issued_Organization_ID>
<core:Partner_Contact_Name_For_This_Model>xxxxxxx</core:Partner_Contact_Name_For_This_Model>
<core:Type_of_Transaction>Initial Certification</core:Type_of_Transaction>
<core:Reason_for_Transaction>Initial Certification: Model Meets ENERGY STAR Requirements</core:Reason_for_Transaction>
<core:Date_of_Transaction_Type>2010-12-31</core:Date_of_Transaction_Type>
<core:ENERGY_STAR_Model_Identifier>TestID2929</core:ENERGY_STAR_Model_Identifier>
<core:Certification_ID>TestCertID123</core:Certification_ID>
<core:Family_ID>TestFamID123</core:Family_ID>
<core:Model_Name>Model_Name1234</core:Model_Name>
<core:Model_Number>Model_Number33453</core:Model_Number>
<core:Brand_Name>Brand_Name1</core:Brand_Name>
<core:Tested_Model_Name>Tested_Model_Name1</core:Tested_Model_Name>
<core:Tested_Model_Number>Tested_Model_Number1</core:Tested_Model_Number>
<!--Zero or more repetitions:-->
<core:Additional_Models_Represented_by_Family_Series_or_DOE_Basic>
<core:Additional_Model_Name>test</core:Additional_Model_Name>
<core:Additional_Model_Number>12345</core:Additional_Model_Number>
<core:Additional_Identifying_Information>non</core:Additional_Identifying_Information>
</core:Additional_Models_Represented_by_Family_Series_or_DOE_Basic>
<core:Is_the_Partner_Listed_the_Original_Equipment_Manufacturer_OEM>Yes</core:Is_the_Partner_Listed_the_Original_Equipment_Manufacturer_OEM>
<core:If_the_Partner_is_Not_the_Original_Equipment_Manufacturer_Who_is>?</core:If_the_Partner_is_Not_the_Original_Equipment_Manufacturer_Who_is>
<core:Currently_Available_on_Market>Yes</core:Currently_Available_on_Market>
<core:Date_Available_On_Market>2010-12-31</core:Date_Available_On_Market>
<core:Date_Tested>2010-12-31</core:Date_Tested>
<core:Date_CB_Notified_Partner_of_Model_Qualification>2010-12-31</core:Date_CB_Notified_Partner_of_Model_Qualification>
<core:Certification_Body_Contact_Name_for_This_Model>QPX Certification Body 1</core:Certification_Body_Contact_Name_for_This_Model>
<!--Zero or more repetitions:-->
<core:Laboratory>
<core:Laboratory_EPA_issued_Organization_ID>xxxxxxxxx</core:Laboratory_EPA_issued_Organization_ID>
<core:Laboratory_Contact_for_This_Model>QPX Laboratory Test</core:Laboratory_Contact_for_This_Model>
</core:Laboratory>
<!--1 to 8 repetitions:-->
<core:To_What_Major_Markets_is_This_Model_Sold>United States</core:To_What_Major_Markets_is_This_Model_Sold>
<core:Notes>notes on the product</core:Notes>
</core:core_product_data>
<roof:ENERGY_STAR_Specification_Version>2.2</roof:ENERGY_STAR_Specification_Version>
<roof:Product_Type>Single-Ply</roof:Product_Type>
<roof:Measured_Initial_Solar_Reflectance>0.25</roof:Measured_Initial_Solar_Reflectance>
<roof:Reported_Initial_Solar_Reflectance>0.26</roof:Reported_Initial_Solar_Reflectance>
<roof:Initial_Solar_Reflectance_Test_Method>ASTM E903-96</roof:Initial_Solar_Reflectance_Test_Method>
<roof:Measured_Solar_Reflectance_After_Three_Years>0.15</roof:Measured_Solar_Reflectance_After_Three_Years>
<roof:Reported_Reflectance_After_Three_Years>0.16</roof:Reported_Reflectance_After_Three_Years>
<roof:Solar_Reflectance_After_Three_Years_Test_Method>ASTM C1549-09</roof:Solar_Reflectance_After_Three_Years_Test_Method>
<roof:Measured_Initial_Emissivity>0.01</roof:Measured_Initial_Emissivity>
<roof:Reported_Initial_Emissivity>0.02</roof:Reported_Initial_Emissivity>
<roof:Initial_Emissivity_Test_Method_Used>ASTM E408-71(1996) e1</roof:Initial_Emissivity_Test_Method_Used>
<roof:Low_Slope>Yes</roof:Low_Slope>
<roof:Steep_Slope>Yes</roof:Steep_Slope>
<roof:Roof_Cleaned_Prior_to_Third_Year_Test>No</roof:Roof_Cleaned_Prior_to_Third_Year_Test>
<roof:Warranty_Period>abcdefg</roof:Warranty_Period>
</roof:Roof_Products>
</roof:Roof_Products_submission>
</soapenv:Body>
</soapenv:Envelope>
EOT;
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
?>
Any and all help would be greatly appreciated.
I'm not sure, if this is correct, but it should be something along these lines:
$namespace = 'https://esws.energystar.gov';
$auth = new ChannelAdvisorAuth($user, $password);
$header = new SoapHeader($namespace, 'APICredentials', $auth, false);
$soap = new SoapClient($url);
$soap->__setSoapHeaders($header);
$soap->DataServices_Server($post_string);
I hope this will point you in the right direction :)