I have been tasked with creating a new web application for internal use at my office. This application has to pull data in from an external website. In order to achieve this we have asked the owners of the external website to produce an xml web service to run over https, which they will write in php. I intend to open up port 443 on our firewall so that our web server can contact this web service.
firstly, my server config:
PHP Version: 5.3.2
Display Errors: On
Error Level: Not E_ALL
Register Globals: Off
Now the XML request that I need to send is very specific - and no wsdl file is available. Please see below:
Code: Select all
<?xml version="1.0" ?> <CustomerDataRequest> <SystemAuthentication> <username>xxxxxxxxxx</username> <password>xxxxxx</password> </SystemAuthentication> <ReferenceNumber>TVL1000582468</ReferenceNumber> </CustomerDataRequest> I have now been told by my boss that we need to move away from old languages such as classic ASP (which I agree with wholeheartedly) and instead I am to do this in PHP.
I'm quite sure that this will be simple enough to achieve in PHP if I use curl, but I dont want to. The only reason I did it like that in ASP is because there was no other way to do it. I want to do it 'better' if that makes sense. PHP has all sorts of extensions for soap and for XML and I want to use them - to future proof myself and my code if for nothing else.
The question is; what extension(s) shall I use? I initially tried PEAR SOAP only to find that it placed everything in the XML into a root node called <item> - which the service at the other end did not like. After some digging I discovered that PEAR had all but abandonned the PEAR SOAP module in favour of the native soap support that had been added to PHP.
I am currently looking at the PHP SOAP extensions - which look better - but it is still formatting the xml requests in the 'wrong' format.
So far the code I have is like this:
Code: Select all
<?phpfunction showarray($input){ echo "<ul>"; foreach($input as $key => $loop){ echo "<li>Index <font color='purple'><b>" . $key . "</b></font> is of type <font color='green'><b>" . gettype($loop) . "</b></font> of value"; if (gettype($loop) == "array") { echo "s:<ul>"; showarray($loop); echo "</ul></li>"; } elseif (gettype($loop) == "boolean") { if ($loop == false) { echo ": <font color='red'><b>False</b></font></li>"; } else { echo ": <font color='red'><b>True</b></font></li>"; } } elseif (gettype($loop) == "string") { echo ": \"<font color='navy'><b>" . $loop . "</b></font>\"</li>"; } else { echo ": <font color='orange'><b>" . $loop . "</b></font></li>"; } } echo "</ul>"; return;} #This is a php webpage designed to test some XML define ("SOURCE_URL","http://xxxxxxxxxxxxxxxx");define ("SOURCE_URI","http://xxxxxxxxxxxxxxxx"); $getclient = new SoapClient (null, array ('location' => SOURCE_URL, 'uri' => SOURCE_URI) ); $Authentication["username"] = "test1234";$Authentication["password"] = "aabcd"; $CustomerDataRequest["SystemAuthantication"] = $Authentication;$CustomerDataRequest["ReferenceNumber"] = "TVL1000582468"; $params = array("CustomerDataRequest" => $CustomerDataRequest); showarray($params); $response = $getclient->soapCall("", $params); echo "<pre>\n";print_r($response);echo "</pre>\n";?> As you can see my array has been built as per the XML file but the XML generated by the PHP SOAP extensions contains a huge amount of text that is superfluous to requirements (and causes the server to fall over!)
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://192.168.91.76:8081/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:soapCall> <param0 xsi:type="xsd:string" /> <param1 xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">CustomerDataRequest</key> <value xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">SystemAuthantication</key> <value xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">username</key> <value xsi:type="xsd:string">test1234</value> </item> <item> <key xsi:type="xsd:string">password</key> <value xsi:type="xsd:string">aabcd</value> </item> </value> </item> <item> <key xsi:type="xsd:string">ReferenceNumber</key> <value xsi:type="xsd:string">TVL1000582468</value> </item> </value> </item> </param1> </ns1:soapCall> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Is it possible to specify the format of the XML? Or am I going about this in completely the wrong way?
Any advice or assistance would be most appreciated. Many thanks for reading.
V.B.R. Ben