从新的 SoapClient 打印 xml



我试图用php构建一个SOAP Web服务,但我有一些问题 我试图在屏幕上打印一个 xml 标头,以便与 Web 服务团队核实是否有效。

我以这种方式创建它:

class WsseAuthHeader extends SoapHeader 
{
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
private $wsp_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
private $wsu_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
function __construct($user, $pass) 
{
$auth = new stdClass();
$auth->username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wsp_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wsu_ns);
//echo "<pre>"; print_r($username_token); exit();
$security_sv = new SoapVar(
new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
}

然后,我尝试调用网络服务并打印 xml:

$client = new SoapClient("http://xxxxxx?wsdl", array('trace' => 1));
$client->__setSoapHeaders(Array(new WsseAuthHeader("myuser", "mypass")));
$result = $client->myfunction(51000286);
echo "REQUEST:n" . $client->__getLastRequest() . "n";

我在手册中看到__getLastRequest(php.net(,但它不起作用 我只能看到"java.lang.NullPointerException">

还有其他方法吗? 我需要生成的 xml 与网络服务人员进行检查。

提前致谢

我可以使用以下方法解决:

$client = new SoapClient("http://xxxxxxx?wsdl", array('trace' => 1,'exceptions'=>0));

最新更新