从php调用asp.net Web服务

时间:2010-03-27 02:51:28

标签: php asp.net

嗨我从php服务调用aps.net web服务。该服务使用搜索参数搜索两个数据库。我不知道如何将搜索参数传递给asp.net服务。代码如下。 (目前没有搜索参数,但我只对将如何传递给asp.net服务感兴趣)

$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

1 个答案:

答案 0 :(得分:0)

你可能想看一下Apache Stonehenge项目,http://www.interoperabilitybridges.com/projects/apache-stonehenge它讨论混合和匹配PHP客户端和web服务,包括来自ASP.NET的那些

JAS