【问题标题】:How to call SOAP API through SOAP client in PHP如何在 PHP 中通过 SOAP 客户端调用 SOAP API
【发布时间】:2016-07-13 18:13:53
【问题描述】:

我正在通过 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);

请建议?我在哪里犯错了?

【问题讨论】:

    标签: php web-services soap soapui soap-client


    【解决方案1】:

    如果您仔细查看请求,您会发现元素 del:ConnInfoXML 包含一个字符串。

    要使其工作,您还必须将ConnInfoXML 设置为字符串:

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

    以编程方式创建字符串时,请务必转义值,以便生成的 XML 有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      相关资源
      最近更新 更多