我被要求使用未记录的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服务,但我不知道为什么userName和密码会以null返回?
我也尝试过:
try {
print($client->__soapCall('Authenticate', array($a, "a", "b")));
} catch (SoapFault $exception) {
echo $exception;
}
无济于事..它仍然说userName为空。
我哪里出错?
答案 0 :(得分:0)
$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服务。这意味着你需要添加&#34; paramaters&#34;同时传递价值观。