Web 服务 - 如何在 PHP 中通过 SOAP 客户端调用 SOAP API


web services - 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
)

以下是我的PHP码:

$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 有效。