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);
开发者_C百科 $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
you might want to look at the Apache Stonehenge project, http://www.interoperabilitybridges.com/projects/apache-stonehenge it talks about mixing and matching PHP clients and webservices including those from ASP.NET
jas
精彩评论