未设置SOAP标头

时间:2014-02-03 06:20:41

标签: php soap wsdl

我正在尝试在SOAP中发送身份验证标头,但它无法正常工作并继续显示“无效身份验证信息”之类的错误。

$options=array(
'senderCity'=>'Atlanta',
'senderState'=>'GA',
'senderZip'=>'30005',
'senderCountryCode'=>'USA',
'receiverCity'=>'Atlanta',
'receiverState'=>'GA',
'receiverZip'=>'30005',
'receiverCountryCode'=>'USA'
            );

$headerbody = array(
        'loginId'=>'xxxxxxxx',
        'password'=>'xxxxxxxx',
        'licenseKey'=>'xxxxxxxxxxxxx',
        'accountNumber'=>'xxxxxxxxxx');

$soap_client = new SoapClient('http://www.wwexship.com/webServices/services/SpeedFreightShipment?wsdl');

$header = new SoapHeader('http://www.wwexship.com/webServices/', 'AuthenticationToken', $headerbody, false);
$soap_client->__setSoapHeaders(array($header)); 

$result = $soap_client->__call('quoteSpeedFreightShipment',$options);

echo "<pre>";
print_r($result);
echo "<pre>";

任何人都可以帮我解决这个问题。

谢谢

2 个答案:

答案 0 :(得分:0)

更正名称空间,

$header = new SoapHeader('http://www.wwexship.com', 'AuthenticationToken', $headerbody, false);

答案 1 :(得分:0)

嗯,我得到了解决方案,所以在此发布....至少保存此解决方案并将其发送给受影响的用户,以便他们可以使用它

测试步骤

  1. 创建PHP页面
  2. 复制代码下方的粘贴
  3. 更改soap_request变量文本中的user,pwd,acct#和key ...
  4. ========================

    <?php
    
    $url = "http://www.wwexship.com/webServices/services/SpeedFreightShipment";
    
    $soap_request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wwex="http://www.wwexship.com">    <soapenv:Header>       <wwex:AuthenticationToken>          <wwex:loginId>LOGIN_ID</wwex:loginId>          <wwex:password>PASSWPRD</wwex:password>          <wwex:licenseKey>LIC_KEY</wwex:licenseKey>          <wwex:accountNumber>ACCT_NUMB</wwex:accountNumber>       </wwex:AuthenticationToken>    </soapenv:Header>    <soapenv:Body>       <wwex:quoteSpeedFreightShipment>          <wwex:freightShipmentQuoteRequest>               <wwex:insuranceDetail xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>                <wwex:senderState>AZ</wwex:senderState>             <wwex:senderZip>85027</wwex:senderZip>              <wwex:senderCountryCode>USA</wwex:senderCountryCode>                <wwex:receiverState>NY</wwex:receiverState>             <wwex:receiverZip>11428</wwex:receiverZip>                  <wwex:receiverCountryCode>USA</wwex:receiverCountryCode>                             <wwex:commdityDetails>                <wwex:is11FeetShipment>N</wwex:is11FeetShipment>                <wwex:handlingUnitDetails>                   <wwex:wsHandlingUnit>                      <wwex:typeOfHandlingUnit>Box</wwex:typeOfHandlingUnit>                      <wwex:numberOfHandlingUnit>1</wwex:numberOfHandlingUnit>                                           <wwex:lineItemDetails>                         <wwex:wsLineItem>                            <wwex:lineItemHazmatInfo xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/><wwex:lineItemClass>50</wwex:lineItemClass>                            <wwex:lineItemWeight>1</wwex:lineItemWeight>                            <wwex:lineItemDescription>Diamond Box</wwex:lineItemDescription>                            <wwex:lineItemPieceType>Pallet</wwex:lineItemPieceType>                            <wwex:piecesOfLineItem>1</wwex:piecesOfLineItem>                         </wwex:wsLineItem>                      </wwex:lineItemDetails>                   </wwex:wsHandlingUnit>                </wwex:handlingUnitDetails>             </wwex:commdityDetails>          </wwex:freightShipmentQuoteRequest>       </wwex:quoteSpeedFreightShipment>    </soapenv:Body> </soapenv:Envelope>';
    
    $header = array(
    "Content-type: text/xml;charset=\"utf-8\"",
    "Accept: text/xml",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "SOAPAction: \"http://www.wwexship.com/webServices/services/SpeedFreightShipment\"",
    "Content-length: ".strlen($soap_request),
    );
    
    $soap_do = curl_init();
    
    curl_setopt($soap_do, CURLOPT_URL, $url);
    curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($soap_do, CURLOPT_POST, true );
    curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
    curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
    
    $result = curl_exec($soap_do);
    
    echo "<pre>".$result."<pre>";
    ?>
    

    ===================================

    如需进一步帮助,请回复@

    http://www.linkedin.com/in/dramilmdodeja

    Dramil Dodeja