使用PHP将请求发送到rightnow webservice的queryCSV方法

时间:2015-06-25 20:14:45

标签: php web-services soap wsdl rightnow-crm

我想发送请求参数&使用PHP SOAP调用的客户端信息头到te右侧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>

我想将客户端标头和参数(query,pagesize,delimiter,returnrawresult,disableMTOM)传递给queryCSV方法。我收到了以下错误:

致命错误:未捕获的SoapFault异常:[soapenv:Sender]消息中的数据元素在index.php(112)中为NULL:SoapClient-&gt; __ soapCall(&#39; QueryCSV&#39;,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);

 ?>

1 个答案:

答案 0 :(得分:0)

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

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

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