2017-08-17 28 views
0

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

我以这种方式创建它:

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

然后,我尝试调用Web服务和打印的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球员。

在此先感谢

+0

好吧,让我们看看我们是否能够把事情说清楚。我认为你想在PHP中构建一个客户端,该客户端使用另一个团队“webservice guys”构建的Web服务。 如果是这样的话,你将会完成相当多的任务。我可以解释如何去做,但在此之前,我首先必须知道这是否是你想要的。 – RWC

+0

我需要看到xml头,因为他们告诉我,xml头是空的,我不这么认为。我想,我的功能应该生成一个“SoapHeader”,我想这是一个xml – Alex

+0

不,这可能不是你应该做的。呦只是应该调用一个Web服务的方法(与你的客户端,你必须建立),然后你可以调查你喜欢的任何东西。哟不应该真的关心标题。如果您可以看到Web服务WSDL,则可以向Web服务发送请求,并且您将收到一个答案,该答案将包含一个标题并且不会为空......为什么'webservice guys'会告诉您标题是空的?什么头? – RWC

回答

0

我可以解决使用:

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