[英]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服務,但是我不知道為什么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服務。 這意味着您需要在傳遞值的同時添加“參數”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.