Call asp.net web service from php

Posted by SamB09 on Stack Overflow See other posts from Stack Overflow or by SamB09
Published on 2010-03-27T02:51:27Z Indexed on 2010/03/27 2:53 UTC
Read the original article Hit count: 323

Filed under:
|

Hi im calling an aps.net web service from a php service. The service searches both databases with a search parameter. Im not sure how to pass a search parameter to the asp.net service. Code is below. ( there is no search paramter currently but im just interested in how it would be passed to the asp.net service)

$link = mysql_connect($host, $user, $passwd);
mysql_select_db($dbName);
$query = 'SELECT firstname, surname, phone, location FROM staff ORDER BY surname';
$result = mysql_query($query,$link);

// if there is a result
if ( mysql_num_rows($result) > 0 ) {
   // set up a DOM object
   $xmlDom1 = new DOMDocument();
   $xmlDom1->appendChild($xmlDom1->createElement('directory'));
   $xmlRoot = $xmlDom1->documentElement;
   // loop over the rows in the result 
   while ( $row = mysql_fetch_row($result) ) {
      $xmlPerson = $xmlDom1->createElement('staff');
      $xmlFname = $xmlDom1->createElement('fname');
      $xmlText = $xmlDom1->createTextNode($row[0]);
      $xmlFname->appendChild($xmlText);
      $xmlPerson->appendChild($xmlFname);
      $xmlSname = $xmlDom1->createElement('sname');
      $xmlText = $xmlDom1->createTextNode($row[1]);
      $xmlSname->appendChild($xmlText);
      $xmlPerson->appendChild($xmlSname);
      $xmlTel = $xmlDom1->createElement('phone');
      $xmlText = $xmlDom1->createTextNode($row[2]);
      $xmlTel->appendChild($xmlText);
      $xmlPerson->appendChild($xmlTel);
      $xmlLoc = $xmlDom1->createElement('loc');
      $xmlText = $xmlDom1->createTextNode($row[3]);
      $xmlLoc->appendChild($xmlText);
      $xmlPerson->appendChild($xmlLoc);
      $xmlRoot->appendChild($xmlPerson);
   }
}

//
// instance a SOAP client to the dotnet web service and read it into a DOM object
// (this really should have an exception handler)
//
$client = new SoapClient('http://stuiis.cms.gre.ac.uk/mk05/dotnet/dataBind01/phoneBook.asmx?WSDL');
$xmlString = $client->getDirectoryDom()->getDirectoryDomResult->any;
$xmlDom2 = new DOMDocument();
$xmlDom2->loadXML($xmlString);

// merge the second DOM object into the first
foreach ( $xmlDom2->documentElement->childNodes as $staffNode ) {
   $xmlPerson = $xmlDom1->createElement($staffNode->nodeName);
   foreach ( $staffNode->childNodes as $xmlNode ) {
      $xmlElement = $xmlDom1->createElement($xmlNode->nodeName);
      $xmlText = $xmlDom1->createTextNode($xmlNode->nodeValue);
      $xmlElement->appendChild($xmlText);
      $xmlPerson->appendChild($xmlElement);
   }
   $xmlRoot->appendChild($xmlPerson);
}

// return result
echo $xmlDom

© Stack Overflow or respective owner

Related posts about php

Related posts about ASP.NET