php中的SOAP请求是什么(添加对象)?


What would be this SOAP request in php (adding an object)

我承认我有点困惑。我需要将下面的SOAP(我假定是。net)转换为php调用(这是与Checkmarx集成- https://checkmarx.atlassian.net/wiki/display/KC/Initiating+a+Session):

)
public void LogAdminIn()
{
    CxSDKWebServiceSoapClient cxSDKProxy = new CxSDKWebServiceSoapClient();
    CxWSResponseLoginData loginResult = cxSDKProxy.Login(new Credentials() { User = "admin@cx", Pass = "admin" }, 1033);
sessionID = loginResult.SessionId;
}

这是我的尝试:

$client = new SoapClient($ServiceURL); 
$param = array(
    'User' => $login,
    'Pass' => $password,
    'lcid' => "1033"
); 
$result = $client->Login(new SoapParam ($param, "Credentials"));
var_dump($result);

但我不相信它实际上是正确的(它不工作,所以我认为它不是)。

我假定了结构,但对它应该是什么感到困惑。

您是否在php.ini文件中启用了soap ?

extension=php_soap.dll移除;

并在脚本中添加:

ini_set('display_errors', 1); 
error_reporting(E_ALL); 
ini_set('soap.wsdl_cache_enabled', '0');
ini_set('soap.wsdl_cache_ttl', '0');

你还需要一些try catch:

try {
    $client = new SoapClient("some.wsdl");
    $result = $client->SomeFunction(/* ... */);
} catch (SoapFault $fault) {
    trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}

检查一下,也许你会有一些提示:)

看起来Login()方法接受两个参数:一个凭据结构和一个整数。你只需要稍微改变一下:

$credentials = array('User' => $login, 'Pass' => $password);
$lcid = 1033;
$result = $client->Login($credentials, $lcid);

如果这不起作用,你也可以尝试使$credentials成为一个对象:

$credentials = new stdClass();
$credentials->User = $login;
$credentials->Pass = $password;
$lcid = 1033;
$result = $client->Login($credentials, $lcid);

在调用之后,检查XML的实际调用并确保请求是正确的是有帮助的:

var_dump($client->__getLastRequest());