我被要求使用未记录的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为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服务。这意味着您需要在传递值的同时添加“参数”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句