2012-01-18 27 views
1

我正在尝试使用PHP进行SOAP请求。看起来我的请求与SOAP服务器文档中详细描述的请求相匹配(但稍有不同的方法),但我得到一个认证错误,就好像头没有被包含一样。为什么我的SOAP请求不工作?

文档的请求样品

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header> 
    <AuthHeader xmlns="http://novosolutions.com/"> 
     <SessionId>string</SessionId> 
    </AuthHeader> 
    </soap:Header> 
    <soap:Body> 
    <ViewTicket xmlns="http://novosolutions.com/"> 
     <Id>int</Id> 
    </ViewTicket> 
    </soap:Body> 
</soap:Envelope> 

请求我的PHP代码输出:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://novosolutions.com/"> 
    <SOAP-ENV:Header> 
     <ns1:AuthHeader> 
      <SessionId>623</SessionId> 
     </ns1:AuthHeader> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <ns1:ViewTicket> 
      <Id>1355110</Id> 
     </ns1:ViewTicket> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

我的PHP代码是相当简单的。难道我做错了什么?

$url = URL_BASE . URL_TICKET . '?WSDL'; 
$soapStruct = new SoapVar(array('SessionId' => SESSION_ID), SOAP_ENC_OBJECT); 
$header = new SoapHeader('http://novosolutions.com/', 'AuthHeader', $soapStruct, false); 

try { 
    $client = new SoapClient($url, array('trace' => 1)); 
} 
catch (SoapFault $exception) { 
    echo 'Exception='.$exception; 
} 
$client->__setSoapHeaders(array($header)); 
var_dump($client); 

$soapData = new SoapVar(array('Id' => 1355110), SOAP_ENC_OBJECT); 
$result = $client->__soapCall('ViewTicket', array('parameters' => $soapData)); 

var_dump($result); 
echo $client->__getLastRequest(); 

编辑: 通过测试用卷曲的要求,我已经将范围缩小到PHP的SoapClient的使用为命名空间的变量的事实。不被SoapServer接受,但是。现在我只需要弄清楚如何防止SoapClient使用变量。

+0

您能找到解决方案吗?我有确切的问题。 – slhsen 2012-09-21 15:00:10

+0

是的 - 我在会话ID中加入了错误的#号。会话ID在响应头中而不是响应主体。为了得到它,使用$ responseHeaders = array(); (''Login',array('parameters'=> $ bodyVar),null,null,$ responseHeaders); $ result = $ client - > __ soapCall $ sessionid = $ responseHeaders ['AuthHeader'] - > SessionId; – 2012-09-21 18:12:23

回答

0

你只是试试这个吗?

error_reporting(E_ALL); 
$client = new SoapClient($url,array('trace' => 1)); 
$client->__setSoapHeaders(new SoapHeader($url, 'SessionId', SESSION_ID)); 
$result = $client->ViewTicket(array('Id'=>1355110)); 
var_dump($result); 
echo '<hr>',str_replace('<','&lt;',$client->__getLastRequest()); 

它会产生什么样的错误信息?

+0

感谢您的回复。没有PHP错误 - 结果是相同的(验证错误或会话已过期)。结果:http://codepad.org/EbQnxKO3 – 2012-01-18 21:35:16

+0

我使用soapUI软件(http://www.soapui.org免费获得它)尝试相同的请求,我得到了相同的结果(认证错误或会话过期)。 ..你确定它不需要凭证? (像一个用户/ pwd HTTP标头)? – sly63 2012-01-19 13:31:36

+0

我几乎已经知道了 - 你知道如何防止PHP的SoapClient使用名称空间的变量吗?我需要而不是 2012-01-21 17:05:13

相关问题