Jump to content
Sign in to follow this  
Sharkadder

Using SOAP with PHP

Recommended Posts

Hi there, I have been looking up on how to use SOAP in relation to php and have managed to hit a bit of a snag with it. Basically on my server i get some information which is presented in xml format from sharepoint. I then wish to access this data from a php file on another server and print it out onto the screen. I have heard using a soap call is the best method for this. The problems i am having are as follows:

  • Gaining authorisation to the xml file i which contains the soap contents i.e. how to log in with username and password
  • Reading the soap content in php to capture some data and print it out

Shown below is a copy of my data which is in an xml format:

<xml><s:Schema id="RowsetSchema"><s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30"><s:AttributeType name="ows_DocIcon" rs:name="Type" rs:number="1"><s:datatype dt:type="string" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows_LinkFilename" rs:name="Name" rs:number="2"><s:datatype dt:type="string" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows_Created" rs:name="Created" rs:number="3"><s:datatype dt:type="datetime" dt:maxLength="8"/></s:AttributeType><s:AttributeType name="ows_Author" rs:name="Created By" rs:number="4"><s:datatype dt:type="string" dt:lookup="true" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows_CheckoutUser" rs:name="Checked Out To" rs:number="5"><s:datatype dt:type="string" dt:lookup="true" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows__x007b_064b332a_x002d_4d9e_x002d_4e7e_x002d_8cf9_x002d_227b6c7972db_x007d_" rs:name="Learner Name" rs:number="6"><s:datatype dt:type="string" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows_StartDate" rs:name="Start Date" rs:number="7"><s:datatype dt:type="datetime" dt:maxLength="8"/></s:AttributeType><s:AttributeType name="ows_JobTitle" rs:name="Job Title" rs:number="8"><s:datatype dt:type="string" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows_Region" rs:name="Region" rs:number="9"><s:datatype dt:type="string" dt:maxLength="512"/></s:AttributeType><s:AttributeType name="ows_Learner_x0020_Email" rs:name="Learner Email" rs:number="10"><s:datatype dt:type="string" dt:maxLength="512"/></s:AttributeType></s:ElementType></s:Schema><z:row ows_DocIcon="xml" ows_LinkFilename="learner_name.xml" ows_Created="2012-03-20 16:26:24" ows_Author="17;#**** *****" ows__x007b_064b332a_x002d_4d9e_x002d_4e7e_x002d_8cf9_x002d_227b6c7972db_x007d_="****** ******" ows_StartDate="2012-03-20 00:00:00" ows_JobTitle="Director" ows_Region="Durham" ows_Learner_x0020_Email="******@hotmail.co.uk"/></rs:data></xml>

Ok so that is the code for one learner record which i am wanting to parse in php...all i want to know is, what do i do to get the learner e-mail address? (the one with the value xxxxx@hotmail.com from the page which requires authorisation to view it. So far i have tried the following with no luck (hashed out the main part of url as contains confidential material):

<?php$xml = simplexml_load_file("http://*********.co.uk:8088/OPS/_vti_bin/owssvr.dll?Cmd=Display&List={6A2E72AB-8F77-4B94-A7FA-DB00527CEFB4}&XMLDATA=TRUE");echo $xml->AttributeType() . "<br />";foreach($xml->children() as $child){echo $child->AttributeType() . ": " . $child . "<br />";}?>

I have also tried the following php code to display the learner name field (that is the name starting with ows__ with letters, underscores and numbers as shown below). it just says failed to load external entity which i am unsure about:

<?php$client = new SoapClient("http://*********.co.uk:8088/OPS/_vti_bin/owssvr.dll?Cmd=Display&List={6A2E72AB-8F77-4B94-A7FA-DB00527CEFB4}&XMLDATA=TRUE", array(trace=>true, 'login'=>"*******", 'password'=>"*****"));$res = $client->row(array('ows__x007b_064b332a_x002d_4d9e_x002d_4e7e_x002d_8cf9_x002d_227b6c7972db_x007d_'=>5));print $res;?>

As you can see i have hashed all of the confidential details out but if somebody could maybe correct my php code so that i can gain access to the file, parse an element from the xml and then display it on the screen then that would be great. Obviously i do have more records but only displayed the first one for demonstration purposes. I also have access to the request and response generated by the server if you wish to see them or maybe point me in the direction on how i can use them instead to print out the values in php. Many thanks, Mark

Edited by Sharkadder

Share this post


Link to post
Share on other sites

That's not SOAP... that's simply PHP accessing an XML file.To use SOAP, you have to create a SOAP server at the IIS end, and a SOAP client at the PHP end. More importantly though, the SOAP server is also responsible for providing a WSDL file, which tells the SOAP client (the PHP end) what objects are available. XML is never used directly by you, but is instead used between the client and server.Doing so is relatively easy for a seasoned ASP.NET programmer, though less so for new comers.If you must use an XML file instead, I'd recommend you use DOM instead of SimpleXML. Once you load() the document, you can use methods like getElementsByTagNameNS() to get the (namespaced) elements you want. SimpleXML isn't really "simple" when namespaces are involved.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×