2013-03-21 64 views
0
设置这个SOAP头

我尝试设置SOAP头是这样的:如何在PHP

<tns:Authentication xmlns:tns="iSklep3"> 
    <ApiKey xsi:type="xsd:string">abc</ApiKey> 
</tns:Authentication> 

我做这样说:

//... 
    $client = new SoapClient($wsdlServer); 
    $headerBody = array("ApiKey" => "abc"); 
    $header = new SoapHeader("iSklep3", "Authentication", $headerBody); 
    $client->__setSoapHeaders($header); 
//... 
//calling soap methods 
... 

当我打电话的方法,它返回API密钥错了,但它应该是对的。知道有人可能会遇到SOAP头问题吗?

+0

我们可以看一看你调用类的任何方式? – Ryoku 2013-03-21 19:12:24

+0

$ res = $ client-> getProductAvailableQuantity($ params); 它返回的Api键是错误的,但API键应该是正确的 – 2013-03-21 19:14:41

+0

或你是什么意思?这是服务的外观http://services.w3.org/xslt?xslfile=http://tomi.vanek.sk/xml/wsdl-viewer.xsl&xmlfile=http://orderapi.beta.i-sklep.pl /soap/order?wsdl&transform=Submit#op.d1e540 – 2013-03-21 19:18:17

回答

1

您没有设置头之后叫通话功能。

<?php 

$client = new SoapClient(null, array('location' => "http://localhost/soap.php", 
            'uri'  => "http://test-uri/")); 
$header = new SoapHeader('http://soapinterop.org/echoheader/', 
          'echoMeStringRequest', 
          'hello world'); 

$client->__setSoapHeaders($header); 

$client->__soapCall("echoVoid", null); 
?> 

来源:RTM http://php.net/manual/en/soapclient.setsoapheaders.php

+0

我有。但它返回,Api Key是错误的。 – 2013-03-21 19:24:26

+0

之前应该提到它。您还需要在__soapCall 发送ApiKey有没有在这个问题的例子:http://stackoverflow.com/questions/1027745/having-trouble-getting-my-head-around-soap-in-php – Ryoku 2013-03-21 19:28:34