简体   繁体   English

如何通过PHP中的SOAP客户端调用SOAP API

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

I am getting successfully response of the SOAP API by the some tools like SoapUI. 我正在通过SoapUI之类的一些工具成功获得SOAP API的响应。 I am working on the deltek API. 我正在使用deltek API。

Following is the code format which i am using in SoapUI 以下是我在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>

But when i am calling the API through the SOAP client in php. 但是,当我通过php中的SOAP客户端调用API时。 I am getting this error : 我收到此错误:

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

Following is my PHPcode : 以下是我的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);

Please suggest? 请提出建议? where am I in making mistake? 我在哪里犯错?

If you look carefully on the request, you can see that the element del:ConnInfoXML contains a string. 如果仔细查看请求,您会发现元素del:ConnInfoXML包含一个字符串。

To make it work, you have to set the ConnInfoXML as string too: 为了使其工作,您还必须将ConnInfoXML设置为字符串:

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

When creating the string programmatically, be sure to escape the values, so the resulting XML is valid. 以编程方式创建字符串时,请确保转义值,因此生成的XML有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM