使用SOAP PHP的WSDL服务器进行身份验证


Authenticating with a WSDL server with SOAP PHP

我被要求使用一个未记录的WebService进行身份验证,我一直在努力让它发挥作用。这就是我迄今为止所做的。

$client = new SoapClient("http://x.x.x.x/dispatch/AuthenticationWebService.asmx?WSDL");
var_dump($client->__getFunctions());
echo "<br>";
var_dump($client->__getTypes()); 
$a["channelType"] = "x";
$b["userName"] = "a";
$c["password"] = "b";
var_dump($a);
var_dump($b);
var_dump($c);
try {
        print($client->__soapCall('Authenticate', array($a, $b, $c)));
} catch (SoapFault $exception) {
        echo $exception;
}

返回:

array(2) { [0]=> string(59) "AuthenticateResponse Authenticate(Authenticate $parameters)" [1]=> string(59) "AuthenticateResponse Authenticate(Authenticate $parameters)" } 
array(5) { [0]=> string(92) "struct Authenticate { BookingChannelType channelType; string userName; string password; }" [1]=> string(25) "string BookingChannelType" [2]=> string(73) "struct AuthenticateResponse { AuthenticationResult AuthenticateResult; }" [3]=> string(116) "struct AuthenticationResult { AuthenticationError Error; string ErrorMessage; boolean Succeeded; string Token; }" [4]=> string(26) "string AuthenticationError" } 

array(1) { ["channelType"]=> string(3) "Web" } array(1) { ["userName"]=> string(10) "RouteMatch" } array(1) { ["password"]=> string(6) "Rm2012" } 

SoapFault exception: [soap:Server] Server was unable to process request. ---> Value cannot be null. Parameter name: userName in /var/www/WebService/test.php:76 Stack trace: #0 /var/www/WebService/test.php(76): SoapClient->__soapCall('Authenticate', Array) #1 {main}

我一辈子都不明白为什么这不起作用?我也试过其他几种组合。。

如果我更改

$a["channelType"] = "Web";

比如

$a["channelType"] = "junk"; 

然后它说。。。

SoapFault exception: [soap:Client] Server was unable to read request. ---> There is an error in XML document (2, 225). ---> Instance validation error: 'Junk' is not a valid value for BookingChannelType. in /var/www/WebService/test.php:71 Stack trace: #0 /var/www/WebService/test.php(71): SoapClient->__soapCall('Authenticate', Array) #1 {main} 

这向我表明数据正在被传递到web服务,但我不知道为什么用户名和密码会返回为null??

我也试过:

try {
        print($client->__soapCall('Authenticate', array($a, "a", "b")));
} catch (SoapFault $exception) {
        echo $exception;
}

没有用。。它仍然表示userName为null。

我哪里错了??

$SoapCallParameters["channelType"] = "x";$SoapCallParameters["userName"] = "a";$SoapCallParameters["password"] = "b";
try {
        $obj = $client->__soapCall("Authenticate", array('parameters'=>$SoapCallParameters));
        var_dump($obj);
} catch (SoapFault $exception) {
        echo $exception;
}

经过一些调查,wsdl web服务是一个.NET服务。这意味着u需要在传递值的同时添加"paramaters"。