从新的SoapClient打印xml

时间:2017-08-17 09:32:38

标签: php xml web-services

我试图在php中构建一个SOAP web服务,但是我遇到了一些问题 我试图在屏幕上打印一个xml标题,以便检查webservice团队是否有效。

我以这种方式创建它:

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);
    }
}

然后,我尝试调用webservice并打印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";

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

还有其他方法吗? 我需要生成的xml与webservice人员一起检查。

提前致谢

1 个答案:

答案 0 :(得分:0)

我可以解决使用:

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