我很难理解如何正确创建soap请求,并从服务器接收信息。
这里是我需要连接的服务的文档链接。它显示了soap请求和响应格式。
https://www.team-intro.com/ws/distributorWS.asmx?op=GetReplicatedSite看着他们的请求格式,我不确定我应该如何将其传递给他们的服务器。我在谷歌上搜索了一下,找到了几种发送请求的方法,但我总是遇到肥皂错误。以下是我的最新尝试。
<?php
//error_reporting(E_ALL);
//soap connect
$client = new SoapClient("http://www.team-intro.com/ws/distributorWS.asmx?WSDL");
$params = new SoapVar("<soap12:Header><AuthHeader Domain='THEDOMAIN' xmlns='http://www.prodogix.com/'><AuthorizationKey>MYAUTHKEY</AuthorizationKey></AuthHeader></soap12:Header><soap12:Body><GetReplicatedSite xmlns='http://www.prodogix.com/'><website>USERNAME</website></GetReplicatedSite></soap12:Body>", XSD_ANYXML);
//$info[
try {
$result = $client->GetReplicatedSite($params);
}
catch (SoapFault $exception) {
echo $exception;
}
print_r($result);
?>
我已经去掉了输入值,并将它们全部替换为大写。
我也看到人们建立一个数组发送到soap服务器,但我似乎无法弄清楚我如何传递额外的信息,如AuthHeader中的域和xmlns。
谁能给我指一下正确的方向?
本教程最终提供了我需要的函数:
http://www.xillent.com/blog/codesharing/php-soap-call-for-wsdl-envelope-and-payload/下面是代码是如何工作的,以防其他人有像我这样的问题。
<?php
//error_reporting(E_ALL);
class feedSoap extends SoapClient
{
var $XMLStr = "";
function setXMLStr ($value){$this->XMLStr = $value; }
function getXMLStr(){return $this->XMLStr; }
function __doRequest($request, $location, $action, $version)
{
$request = $this -> XMLStr;
$dom = new DOMDocument('1.0');
try
{
$dom->loadXML($request);
}
catch (DOMException $e)
{
die($e->code);
}
$request = $dom->saveXML();
//doRequest
return parent::__doRequest($request, $location, $action, $version);
}
function SoapClientCall($SOAPXML)
{
return $this -> setXMLStr ($SOAPXML);
}
}
function soapCall($wsdlURL, $callFunction="", $XMLString)
{
$client = new feedSoap($wsdlURL, array('trace' => true));
$reply = $client-> SoapClientCall($XMLString);
$client->__call("$callFunction", array(), array());
return $client -> __getLastResponse();
}
//i just copied the soap request they provided and dropped in my values (removed for stackoverflow
$XMLString= '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader Domain="THEDOMAIN" xmlns="http://www.prodogix.com/">
<AuthorizationKey>MYKEY</AuthorizationKey>
</AuthHeader>
</soap:Header>
<soap:Body>
<GetReplicatedSite xmlns="http://www.prodogix.com/">
<website>USERSNAMEe</website>
</GetReplicatedSite>
</soap:Body>
</soap:Envelope>';
//set up the url to post the soap request to
$wsdlURL = 'https://www.team-intro.com/ws/distributorWS.asmx?WSDL';
//make the call, and set the soap function that I'll be using
$result = soapCall($wsdlURL, $callFunction="GetReplicatedSite", $XMLString);
print_r($result);
?>