0
嗨,我正在从php服务调用aps.net web服务。该服务使用搜索参数搜索两个数据库。我不知道如何将搜索参数传递给asp.net服务。代码如下。 (目前还没有搜索放慢参数,但即时通讯在它如何被传递到asp.net服务只是有兴趣)从php调用asp.net web服务
$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
不回答你的问题,但是这是使用OData的http://blogs.msdn.com/interoperability/archive/2010/03/一个完美的方案16/OData兼容互操作性与净java的PHP-iphone和 - more.aspx – 2010-03-27 02:53:13