簡體   English   中英

如何通過PHP中的SOAP客戶端調用SOAP API

[英]How to call SOAP API through SOAP client in PHP

我正在通過SoapUI之類的一些工具成功獲得SOAP API的響應。 我正在使用deltek API。

以下是我在SoapUI中使用的代碼格式

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:del="http://tempuri.org/Deltek.Vision.WebServiceAPI.Server/DeltekVisionOpenAPIWebService">
   <soap:Header/>
   <soap:Body>
      <del:GetSchema>
         <!--Optional:-->
         <del:ConnInfoXML><![CDATA[<VisionConnInfo>
<databaseDescription>Example_Test (TEST_001)</databaseDescription>
<userName>test</userName>
<userPassword>test123</userPassword>
<integratedSecurity>Y</integratedSecurity>
</VisionConnInfo>]]> </del:ConnInfoXML>

         <!--Optional:-->
         <del:InfoCenter><![CDATA[User]]></del:InfoCenter>
      </del:GetSchema>
   </soap:Body>
</soap:Envelope>

但是,當我通過php中的SOAP客戶端調用API時。 我收到此錯誤:

stdClass Object
(
    [GetSchemaResult] => ErrLoginValInvalid login. Please change the username or password and try again.Value cannot be null.
Parameter name: sGetSchema.validateVisionLogin.VisionWSUtil.ValidateVisionLogin
)

以下是我的PHPcode:

$apiURL = 'http://example.com/Vision/VisionWS.asmx?wsdl';
$client = new SoapClient($apiURL, array('trace' => 1, 'exceptions' => 1));

$conninfo = array(
           'ConnInfoXML' => array(
             'VisionConnInfo' => array(
               "databaseDescription"  => 'Example_Test (TEST_001)',
               "userName" => "test", 
               "userPassword" => 'test123',
               "integratedSecurity" => "Y"   
               )
            )
          );

$userinfo  = array('InfoCenter' => 'User');

try {

    $result = $client->GetSchema($conninfo, $userinfo);
} catch (SoapFault $fault) {
    print_r($fault);
}

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

請提出建議? 我在哪里犯錯?

如果仔細查看請求,您會發現元素del:ConnInfoXML包含一個字符串。

為了使其工作,您還必須將ConnInfoXML設置為字符串:

'ConnInfoXML' => '<VisionConnInfo>...</VisionConnInfo>';

以編程方式創建字符串時,請確保轉義值,因此生成的XML有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM