I am currently trying to work with a 3rd party vendor that requires the use of SOAP requests. The vendor's site says: I've looked all around at the SOAPClient manual on php.net and just find myself getting more and more confused. Their documentation really lacks commenting sometimes. If anybody can get me pointed in the right direction I would really appreciate it. I may not have supplied enough info, so if more info is needed, please let me know!
Double check that you specifically need SOAP and not just an XML post. You can use CURL to post XML data to an API, and then parse the response using simplexml or domxml, or another parser, which is significantly easier that SOAP.
Here's what I've got so far but it keeps throwing the error of "Unable to handle request without a valid action parameter. Please supply a valid soap action." <?php error_reporting(E_ALL | E_STRICT | E_NOTICE); $requestString = file_get_contents('soap_data.xml'); echo '<pre>'; try { $soap = new SoapClient( 'https://aissreports.acxiom.com/xmlbackgroundtests/xmlresults.asmx?wsdl', array('login' => 'user', 'password' => 'pass') ); echo htmlentities( $soap->__doRequest($requestString, 'https://aissreports.acxiom.com/XMLBackgroundTests/Request.asmx', 'https://aissreports.acxiom.com/XMLBackgroundTests/SubmitRequest', SOAP_1_2) ); } catch (SoapFault $fault) { var_dump( htmlentities($fault) ); } catch (Exception $e) { var_dump( htmlentities($e) ); } echo '</pre>'; ?> PHP: This is the full response that is output by the browser <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>Unable to handle request without a valid action parameter. Please supply a valid soap action.</faultstring> <detail /> </soap:Fault> </soap:Body> </soap:Envelope> Code (markup):
Yeah, you are using the built in SOAP. I just used NuSOAP. Basic of what you are missing is that you have to send the header first, best info I could find was of course on php.net. Much more complicated than it should be though. http://us3.php.net/manual/en/soapheader.soapheader.php If that doesn't help, here's a start on doing auth with nusoap... http://www.beanizer.org/site/index.php/en/Articles/NuSOAP-HTTP-Authentication-and-HTTP-Proxy.html
Any chance you could give me an example on how to send the header first with my example code above? Thanks for everything!
Um, best I could would be to pull one of those examples from php.net. but I ain't sure the code you got above is 100% right so odds are its going to be more confusing than helpful. First create the header class .... class authentication_header { private $username; private $password; public function __construct($username,$password) { $this->username=$username; $this->password=$password; } } Code (markup): Actually assign the user/pass to vars ... $auth=new authentication_header('myuser','secret'); Apparently you have to encapsulate the variables (>?>) $authvalues=new SoapVar($auth,SOAP_ENC_OBJECT,'authenticate'); Then you generate the header $header=new SoapHeader("myURN", "authenticate", $authvalues, false, "https://aissreports.acxiom.com/XMLBackgroundTests/Request.asmx"); Code (markup): And I'm just guessing on the correct URI. The docs from the web service should tell you which is correct. $requestString = file_get_contents('soap_data.xml'); This needs to be put into the parameters, should be array. check the docs for correct way to do it. $params = array("fileasstring" =>$requestString); $soap = new SoapClient( 'https://aissreports.acxiom.com/xmlbackgroundtests/xmlresults.asmx?wsdl'); Final part is make the call : $soap->__call('SubmitRequest', $params, null, $header); Course I haven't used that method so its probably all wrong.
I'm not sure if I did everything like you stated or in the correct order. Code is below. I'm getting the following error when I run the code I'm using myuname and mypass for username and password. (wasn't sure where you wanted me to plug them in at). <?php class authentication_header { private $username; private $password; public function __construct($username,$password) { $this->username=$username; $this->password=$password; } } $auth=new authentication_header('myuname','mypass'); $authvalues=new SoapVar($auth,SOAP_ENC_OBJECT,'authenticate'); $header=new SoapHeader("myURN", "authenticate", $authvalues, false, "https://aissreports.acxiom.com/XMLBackgroundTests/Request.asmx"); $params = array("fileasstring" =>$requestString); $soap = new SoapClient( 'https://aissreports.acxiom.com/xmlbackgroundtests/xmlresults.asmx?wsdl'); $soap->__call('SubmitRequest', $params, null, $header); ?> PHP:
Looks right, its just telling us that it doesn't accept the SubmitRequest as a viable function. the company running the webservice should have provided docs for their specific interface with the functions listed. You need to check that.