首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PHP和wsdl2php添加SOAP标头

使用PHP和wsdl2php添加SOAP标头
EN

Stack Overflow用户
提问于 2011-09-15 18:28:40
回答 2查看 3.9K关注 0票数 0

我完全是PHP编程的新手,但我的任务是编写一个示例PHP服务客户机,该客户机使用我公司用Java编写的web服务。我们有两种类型的服务。我已经使用wsdl2php库成功地与不需要身份验证的服务进行了通信。我们的安全服务要求我向我的请求添加一个SOAP标头,如下所示:

代码语言:javascript
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sen="https://webservices.averittexpress.com/SendWebImageService"> 
    <soapenv:Header xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
        <ns:authnHeader soapenv:mustUnderstand="0" xmlns:ns="http://webservices.averittexpress.com/authn"> 
            <Username>xxxxxxxx</Username> 
            <Password>xxxxxxxx</Password> 
        </ns:authnHeader> 
    </soapenv:Header> 

我遇到的问题是,我不知道如何使用wsdl2php做到这一点,甚至不知道它是否可行。下面是我当前用来测试的PHP文件。

代码语言:javascript
复制
<?php

require_once 'LTLRateQuoteService.php';

$rqs = new LTLRateQuoteService();
$info = new ShipmentInfo();
$HeaderSecurity = array("authnHeader"=>array("UserName"=>"xxxxxx",
                                             "Password"=>"xxxxxx",));

$header[] = new SoapHeader("http://schemas.xmlsoap.org/soap/encoding",
                           "Header",$HeaderSecurity);

$rqs->__setSoapHeaders($header);

$args = new AvtLTLRateQuoteRequest();
$args->AccountNumber = '1234578';
$args->OriginCity = 'Cookeville';
$args->OriginState = 'TN';
$args->OriginZip = '38501';
$args->DestinationCity = 'Morristown';
$args->DestinationState = 'TN';
$args->DestinationZip = '37814';
$args->ShipDate = '12/12/2011';
$args->Customer = 'S';
$args->PaymentType = 'P';

$info->NumPieces = '1';
$info->NumHandling = '1';
$info->CubicFeet = '1';
$info->Items = '1';
$info->TotalItem = '1';
$info->TotalWeight = '100';
$args->ShipmentInfo = $info;

$grq = new getLTLRate();
$grq->arg0 = $args; 

$response = $rqs->getLTLRate($grq);
$details = $response->return;
print 'Total Freight Charge: ' . $details->TotalFreightCharge . ' ';
?>

我需要以某种方式将用户名和密码附加到此请求的标题,但不知道如何做。我浏览了wsdl2php站点,关于如何使用该库的文档很少。任何帮助都将不胜感激。

谢谢,

安德鲁

EN

回答 2

Stack Overflow用户

发布于 2016-01-23 02:46:47

不要在没有答案的情况下听那些粗鲁的评论巨魔,只听侮辱。这就是我是如何做到的。

代码语言:javascript
复制
function __construct($url='wsdl url')
 {
    $auth=array('AccountUsername'=>'test','AccountPW'=>'test');
    $authvalues = new \SoapVar($auth, SOAP_ENC_OBJECT);
    $header =  new \SoapHeader('http://www.nsurl.com/', 
                                'AuthenticationHeader', // Rename this to the tag you need
                                $authvalues, false);

    $this->soapClient = new SoapClient($url,array("classmap"=>self::$classmap,"trace" => true,"exceptions" => true));
    $this->soapClient->__setSoapHeaders(array($header));
    //set the Headers of Soap Client.
    //$this->soapClient->__setSoapHeaders($header);
}
票数 2
EN

Stack Overflow用户

发布于 2011-09-16 01:49:18

与使用wsdl2php相比,使用PHP的内部SOAP函数会更好吗?

http://php.net/manual/en/class.soapclient.php

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7429418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档