2013-02-08 16 views
9

PHPのビルトインソープ関数を使用してAPIにログインしようとしています。私はこのような結果を得た。soap:Envelope SOAP-ENV:Envelope PHP

[LoginResult]=> false, 
[ErrorMsg] => Login failed with the reason : The security object is invalid 

これはAPIプロバイダが必要とするものです。

<?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> 
    <Login xmlns="http://tempuri.org/Example/Service1"> 
      <objSecurity> 
       <WebProviderLoginId>test</WebProviderLoginId> 
       <WebProviderPassword>test</WebProviderPassword> 
       <IsAgent>false</IsAgent> 
      </objSecurity> 
      <OutPut /> 
      <ErrorMsg /> 
    </Login> 
</soap:Body> 
</soap:Envelope> 

&ここでは、関数を使用して生成できたものを示します。

ここにはリクエストを送信するために使用したコードがあります。

<?php 
class objSecurity { 
function objSecurity($s, $i, $f) { 
    $this->WebProviderLoginId = $s; 
    $this->WebProviderPassword = $i; 
    $this->IsAgent = $f; 
} 
} 

class nextObject { 
function nextObject($objSecurity) { 
    $this->objSecurity=$pobjSecurity; 
    $this->OutPut=NULL; 
    $this->ErrorMsg=NULL; 
} 
} 

$url = 'http://example.com/sampleapi/test.asmx?WSDL'; 
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1)); 
$struct = new objSecurity('test', 'test', false); 
$data = new nextObject($struct); 
$soapstruct2 = new SoapVar($data, SOAP_ENC_OBJECT); 
print_r(
    $client->__soapCall(
     "Login", 
     array(new SoapParam($soapstruct2, "inputStruct")) 
    ) 
); 

echo $client->__getLastRequest(); 

?> 

これらは私が見つけた違いです。

私の要求でxmlns:xsiがありません。

要件は<soap:Envelopeで始まりますが、私の要求は<SOAP-ENV:Envelopeで始まります。

ご要望にはxmlns:ns1があります。

&ファンクション名タグは、ns1:で始まります。

私の要求を必要な形式にするのを手伝ってください。

私はSOAPについてよく分かりません.CakePHP 2.3.0でPHP 5.3.13を使用しています。申し訳ありませんが、私の悪い英語です。

+0

**私は私の答え**を得ましたが、サイトはそれが8時間後にしか投稿できないと言っています... :( – KrIsHnA

+0

あなたはそれを理解したように思えます。答え、しかし、FYI、これらの2つのXMLの例は、まともなXMLハンドラの観点からかなり同等です。 – JLRishe

答えて

11

ここに解決策があります。 :)

<?php 
$url = 'http://example.com/sampleapi/test.asmx?WSDL'; 
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1)); 

$user_param = array (
    'WebProviderLoginId' => "test", 
    'WebProviderPassword' => "test", 
    'IsAgent' => false 
); 

$service_param = array (
    'objSecurity' => $user_param, 
    "OutPut" => NULL, 
    "ErrorMsg" => NULL 
); 

print_r(
    $client->__soapCall(
     "Login", 
     array($service_param) 
    ) 
); 

echo $client->__getLastRequest(); 

?> 

&要求されました:このリンクに

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1"> 
<SOAP-ENV:Body> 
    <ns1:Login> 
     <ns1:objSecurity> 
      <ns1:WebProviderLoginId>test</ns1:WebProviderLoginId> 
      <ns1:WebProviderPassword>test</ns1:WebProviderPassword> 
      <ns1:IsAgent>false</ns1:IsAgent> 
     </ns1:objSecurity> 
    </ns1:Login> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

感謝。 PHP SOAP Request not right

+0

素晴らしい!!!あなたはあなた自身の質問、献身(y)を解決しました。 – Krish