1

我想使用 PHP SOAP 调用将请求参数和客户端信息标头发送到 te rightnow webservice。我怎样才能做到这一点 ?请帮忙

我的wsdl结构如下:

<wsdl:operation name="QueryCSV">
            <soap:operation soapAction="QueryCSV" style="document"/>
            <wsdl:input>
                <soap:body parts="parameters" use="literal"/>
                <soap:header message="rnw_v1_2:ClientInfoHeader" part="request_header" use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>

我想将客户端标头和参数(查询、页面大小、分隔符、returnrawresult、disableMTOM)传递给 queryCSV 方法。我收到以下错误:

致命错误:未捕获的 SoapFault 异常:[soapenv:Sender] 消息中的数据元素在 index.php(112) 中为 NULL:SoapClient->__soapCall('QueryCSV', Array) #1 {main} 在 index.php 中抛出

我尝试了几种方法,其中一种方法是:

<?php

class clsWSSEAuth {
          private $Username;
          private $Password;
        function __construct($username, $password) {
                 $this->Username=$username;
                 $this->Password=$password;
              }
}

class clsWSSEToken {
        private $UsernameToken;
        function __construct ($innerVal){
            $this->UsernameToken = $innerVal;
        }
}

class ClientInfoHeader {
         private $AppID;
         function __construct ($appid){
             $this->AppID = $appid;
        /}
}


$username = "***";
$password = "***";
$WSDL = "https://*****/services/soap?wsdl";
$arrOptions = array('trace' => true);
$appid = "*****";


// SECURITY NAMESPACE
$strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

//client infoheader namespace
$v1 = "urn:wsdl.ws.rightnow.com/v1_2";

$objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);

$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
$objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);

// token object
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
$objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
$objSoapVarHeaderVal = new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);

# Create the ClientInfoHeader header
$objAppId = new SoapVar($appid, XSD_STRING, NULL, $v1, NULL, $v1);
$objClientInfoHeader = new SoapVar($objAppId, SOAP_ENC_OBJECT, NULL, $v1, 'ClientInfoHeader', $v1);


//soap header
$objSoapVarWSSEHeader = array();
$objSoapVarWSSEHeader[] = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal, true);
$objSoapVarWSSEHeader[] = new SoapHeader($v1, 'ClientInfoHeader', $objClientInfoHeader);

$objClient = new SoapClient($WSDL, $arrOptions);
//set headers
$wss_header = $objClient->__setSoapHeaders($objSoapVarWSSEHeader);


 $Query = "select ********** from ******** where id > *** ";
 $PageSize = 50;
 $Delimiter = '|';
 $ReturnRawResult = false;
 $DisableMTOM = true;

 $params = array('Query' => $Query, 'PageSize' => $PageSize, 'Delimiter' => $Delimiter, 'ReturnRawResult' => $ReturnRawResult, 'DisableMTOM' => $DisableMTOM);


 $objResponse = $objClient->__soapCall("QueryCSV", array('parameters' => $params));
 var_dump($objResponse);

 ?>
4

1 回答 1

0

此错误意味着您的 XML 正文缺少消息节点。您是否能够捕获构造的 SOAP 主体并在此处输出?

我建议您改变使用 cURL 和一组可能具有动态参数的 SOAP 信封消息的方法,而不是使用 SOAPClient。您可以使用 SOAP UI 来构建 XML,然后将其放入您的代码用来填充所需节点的文件中。

当像 SOAP Client 这样的工具应该提供帮助时,很难证明对消息进行硬编码是合理的,但我看到的问题比使用 OSvC WSDL 的 SOAPClient 方法的解决方案要多。Ruby 的 SOAP gem 比 PHP 中的 SOAPClient 更好地处理 OSvC WSDL。

于 2015-06-26T15:08:28.590 回答