致命错误:Uncaught SoapFault exception: [Client] error finding &q


Fatal error: Uncaught SoapFault exception: [Client] Error finding "uri" property in

标题给了我一些SO链接,但不幸的是我不能让他们工作。我对SOAP完全陌生。我已经给了一个wsdl链接,有一些方法,我需要通过soap调用。

我被卡在一个特定的点上,它说

Uncaught SoapFault exception: [Client] Error finding "uri" property in此代码正在生成错误。

class SoapClientCompatibility extends SoapClient{
    public function __construct($wsdl, $options){
        // do things here, like:
        // download the wsdl using curl
    }}function soapClientWSSecurityHeader($user, $password){
  // Creating date using yyyy-mm-ddThh:mm:ssZ format
  $tm_created = gmdate('Y-m-d'TH:i:s'Z');
  $tm_expires = gmdate('Y-m-d'TH:i:s'Z', gmdate('U') + 180); //only necessary if using the timestamp element
  // Generating and encoding a random number
  $simple_nonce = mt_rand();
  $encoded_nonce = base64_encode($simple_nonce);
  // Compiling WSS string
  $passdigest = base64_encode(sha1($simple_nonce . $tm_created . $password, true));
  // Initializing namespaces
  $ns_wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  $ns_wsu = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
  $password_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest';
$encoding_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
  // Creating WSS identification header using SimpleXML
  $root = new SimpleXMLElement('<root/>');
  $security = $root->addChild('wsse:Security', null, $ns_wsse);
  //the timestamp element is not required by all servers
  $timestamp = $security->addChild('wsu:Timestamp', null, $ns_wsu);
  $timestamp->addAttribute('wsu:Id', 'Timestamp-28');
  $timestamp->addChild('wsu:Created', $tm_created, $ns_wsu);
  $timestamp->addChild('wsu:Expires', $tm_expires, $ns_wsu);
  $usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
  $usernameToken->addChild('wsse:Username', $user, $ns_wsse);
  $usernameToken->addChild('wsse:Password', $passdigest, $ns_wsse)->addAttribute('Type', $password_type);
  $usernameToken->addChild('wsse:Nonce', $encoded_nonce, $ns_wsse)->addAttribute('EncodingType', $encoding_type);
  $usernameToken->addChild('wsu:Created', $tm_created, $ns_wsu);

  // Recovering XML value from that object
  $root->registerXPathNamespace('wsse', $ns_wsse);
  $full = $root->xpath('/root/wsse:Security');
  $auth = $full[0]->asXML();
  print_r($auth);
  return new SoapHeader($ns_wsse, 'Security', new SoapVar($auth, XSD_ANYXML), true,'https://mywebsite.com');
}
class Valid {
    function Valid($hn, $vc) 
    {
        $this->healthNumber = $healthNumber;
        $this->versionCode = $versionCode;
    }
}
$hcvRequest = array(
    "healthNumber" => "1286844022",
    "versionCode" => "YX"
);
$valid = array(
    "hcvRequest" => $hcvRequest
);
$params = array(
    "requests" => $valid
);
$client = new SoapClientCompatibility('https://example.com/?wsdl');$client->__setSoapHeaders(soapClientWSSecurityHeader('someemail@email.com', 'somepassword'));
echo "<pre>";
$response = $client->__soapCall("validate", array($params));
print_r($client);
print_r($response);

我发现这个页面,因为我得到了Error finding "uri" property的异常,而使用php SoapClient。

最后,对我来说,我发现这个错误是由于我引用的WSDL文件的保存版本(保存在本地)已经过期。web服务已经更改,所以一旦我删除了本地WSDL文件并拉下它的最新版本,错误就不再发生了。

希望这将帮助任何php SoapClient用户谁有相同的问题。

注意,我将WSDL文件的本地存储版本传递给SoapClient的第一个参数。我相信这意味着SoapClient不会在每个Soap请求时都拉下WSDL文件。