2011-09-15 19 views
0

私はPHPプログラミングの完全な新参ですが、Javaで書かれた私の会社のWebサービスを使用するサンプルのPHP Webサービスクライアントを作成することに取り組んでいます。私たちには2種類のサービスがあります。認証が必要なものとそうでないもの。私はwsdl2phpライブラリを使用して、認証を必要としないサービスと正常に通信しました。PHPとwsdl2phpでSOAPヘッダーを追加

<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でこれを行うには考えているということですかそれも可能な場合:私たちの安全なサービスは、私はこのようになります私の要求にSOAPヘッダを追加する必要があります。私が現在テストしているPHPファイルは次のとおりです。

<?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サイトを見ていて、ライブラリの使い方に関するドキュメントはほとんどありません。どんな助けもありがとう。

むしろ、その後のおかげで、

アンドリュー

+0

なぜnewbsがWebサービスに入りますか?または、あなたのシェフがウェブサービスを書くために完全なnewbに頼んでしまうほど巧妙なのでしょうか? –

+0

私はWebサービスを作成していません。私たちはJavaの家です。私たちはJavaでWebサービスを作成しました。 PHPを使用して接続するサービスを使用するクライアントがあります。私は単純にPHPで簡単なクライアントを作成しようとしています。私はセキュリティで保護されていないクライアントを正常に動作させるようにしました。私はちょうど認証を必要とするものに悩まされています。 –

+0

私はこれと同じ問題を抱えています。誰でも助けてくれます。 –

答えて

0

PHPの社内SOAP関数を使用してしまう、wsdl2phpを使用しては良い仕事しますか?

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

+0

まだヘッダーを作成する必要があり、それは動作しません。 –

+0

http://www.php.net/manual/en/soapclient.setsoapheaders.php#93460は指示を与えるようです。 – Drazisil

1

、答えずに失礼なコメント荒らしにのみ侮辱を聞いてはいけません。ここで私はそれをやった方法です。

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); 
} 
関連する問題