2017-04-03 8 views
1

シンプルなSOAPクライアントを作成するためのチュートリアルを試して読んでから半日を過ごした後、私はAPIからのリクエストを取得しようとしていません。PHP SOAPクライアントで本体が作成されない

WSDL:上記のこれは、予想されるデータを返す

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pub="http://publicapi.ekmpowershop.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <pub:GetOrders> 
     <!--Optional:--> 
     <pub:GetOrdersRequest> 
       <!--Optional:--> 
      <pub:APIKey>myApiKey</pub:APIKey> 
     </pub:GetOrdersRequest> 
     </pub:GetOrders> 
    </soapenv:Body> 
</soapenv:Envelope> 

http://publicapi.ekmpowershop31.com/v1.1/publicapi.asmx?WSDL

私は、次のような単純なSOAPリクエストとSOAP UIからの要求を行うことができます。

それは私が次のことを持っているPHPに要求を翻訳しています:

$wsdl = 'http://publicapi.ekmpowershop31.com/v1.1/publicapi.asmx?WSDL'; 
$trace = true; 
$exceptions = false; 
$debug = true; 

$client = new SoapClient($wsdl, 
     array(
     'trace' => $trace, 
     'exceptions' => $exceptions, 
     'debug' => $debug, 
    )); 


$param = array('GetOrdersRequest' => array(
       'APIKey' => 'myApiKey' 
      ) 
     ); 

$resp = $client->GetOrders(); 

print_r($param); 
print_r($client->__getLastRequest()); 
print_r($client->__getLastResponse()); 

その後、GetOrders関数に$のPARAMを置く場合は、それが壊れると、何も起こりません。

$ client-> GetOrders(array( 'someArry' => $ param))で配列を使用しても、レスポンスとリクエストは常に同じように見えますが、SOAPリクエストの本文は決して作成されません:

要求:

?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://publicapi.ekmpowershop.com/"><SOAP-ENV:Body><ns1:GetOrders/></SOAP-ENV:Body></SOAP-ENV:Envelope> 

応答:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetOrdersResponse xmlns="http://publicapi.ekmpowershop.com/"><GetOrdersResult><Status>Failure</Status><Errors><string>Object reference not set to an instance of an object.</string></Errors><Date>2017-04-03T16:00:42.9457446+01:00</Date><TotalOrders>0</TotalOrders><TotalCost xsi:nil="true" /></GetOrdersResult></GetOrdersResponse></soap:Body></soap:Envelope> 

誰が本当の大きな助けになり、私はここで間違ってやっているかについていくつかの光を当てることができますか?

P.S私はJava環境でSOAPに慣れているので、PHPでのSOAPの経験は限られています。ありがとう

答えて

0

$client->GetOrders()コールにパラメータを渡す必要があります。また、WSDLは、いくつかの必要なパラメータを定義するので、最小限の例のようなものです:

<Errors><string>Invalid character in a Base-64 string.</string></Errors> 

私のAPIキーが無効であるため、おそらくです:

$wsdl = 'http://publicapi.ekmpowershop31.com/v1.1/publicapi.asmx?WSDL'; 
$trace = true; 
$exceptions = false; 
$debug = true; 

$client = new SoapClient($wsdl, 
     array(
     'trace' => $trace, 
     'exceptions' => $exceptions, 
     'debug' => $debug, 
    )); 


$param = array(
    'GetOrdersRequest' => array(
     'APIKey' => 'dummy-key', 
     'CustomerID' => 1, 
     'ItemsPerPage' => 1, 
     'PageNumber' => 1, 
    ) 
); 

$resp = $client->GetOrders($param); 


print_r($param); 
print_r($client->__getLastRequest()); 
print_r($client->__getLastResponse()); 

これは、エラー応答を与えます。

+0

ありがとうございます、あなたは命の恩人です! – breakworm

+0

WSDLにminOccursのように余分なフィールドを含める必要があることを理解していますが、これらのパラメータ(CustomerID、ItemsPerPage、PageNumber)を除外すると、SOAP UIによるリクエストはなぜ機能しますか?特定の顧客の注文よりも便利なSOAP UIのすべての注文を返します。おそらくSOAPにワイルドカードのデフォルトがありますか? – breakworm

+0

ああ値を空の文字列として残すと、すべての注文がWebサービスから返されます。再度、感謝します! – breakworm

関連する問題