作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
// Based on http://stackoverflow.com/questions/3934639/soap-authentication-with-php
include 'auth.php';
$soapURL = "http://traindata.njtransit.com:8090/NJTTrainData.asmx?WSDL" ;
$soapParameters = array('UserCredentials'=>array('userName' => $username, 'password' => $password));
$soapFunction = "getTrainScheduleJSON" ;
$soapFunctionParameters = Array('station' => "NY") ;
$soapClient = new SoapClient($soapURL, $soapParameters);
$soapResult = $soapClient->__soapCall($soapFunction, $soapFunctionParameters);
PHP Fatal error: Uncaught SoapFault exception: [soap:MustUnderstand] System.Web.Services.Protocols.SoapHeaderException: Missing required header 'UserCredentials'.
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest() in /home/www/html/njtransit/wed.php:13
Stack trace:
#0 /home/www/html/njtransit/wed.php(13): SoapClient->__soapCall('getTrainSchedul...', Array)
#1 {main}
thrown in /home/www/html/njtransit/wed.php on line 13
include 'auth.php';
$soapURL = "http://traindata.njtransit.com:8090/NJTTrainData.asmx?WSDL" ;
$ns = 'http://microsoft.com/webservices/'; //Namespace of the WS.
$soapParameters = array('UserCredentials'=>array('userName' => $username, 'password' => $password));
$soapFunction = "getTrainScheduleJSON" ;
$soapFunctionParameters = Array('station' => "NY") ;
// $soapClient = new SoapClient($soapURL, $soapParameters);
$soapClient = new SoapClient($soapURL);
$header = new SoapHeader($ns,'UserCredentials',$soapParameters,false);
$soapClient->__setSoapHeaders($header);
var_dump($soapClient);
$soapResult = $soapClient->__soapCall($soapFunction, $soapFunctionParameters);
object(SoapClient)#1 (3) {
["_soap_version"]=>
int(1)
["sdl"]=>
resource(5) of type (Unknown)
["__default_headers"]=>
array(1) {
[0]=>
object(SoapHeader)#2 (4) {
["namespace"]=>
string(33) "http://microsoft.com/webservices/"
["name"]=>
string(15) "UserCredentials"
["data"]=>
array(1) {
["UserCredentials"]=>
array(2) {
["userName"]=>
string(10) "myusername"
["password"]=>
string(17) "mypassword"
}
}
["mustUnderstand"]=>
bool(false)
}
}
}
PHP Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at DepartureVisionServiceXMLExternal.ServiceExternal.Login(String username, String password) in C:\Users\vcaicxz\Desktop\CRYSTAL\PentaDepartureVisionServiceXMLExternaL\NJTTrainData.asmx.cs:line 55
at DepartureVisionServiceXMLExternal.ServiceExternal.getTrainScheduleJSON(String station) in C:\Users\vcaicxz\Desktop\CRYSTAL\PentaDepartureVisionServiceXMLExternaL\NJTTrainData.asmx.cs:line 141
--- End of inner exception stack trace --- in /home/www/html/njtransit/wed2.php:19
Stack trace:
#0 /home/www/html/njtransit/wed2.php(19): SoapClient->__soapCall('getTrainSchedul...', Array)
#1 {main}
thrown in /home/www/html/njtransit/wed2.php on line 19
最佳答案
你快到了,这一行:
$header = new SoapHeader($ns,'UserCredentials',$soapParameters,false);
UserCredentials
节点,所以这一行:
$soapParameters = array('UserCredentials'=>array('userName' => $username, 'password' => $password));
$soapParameters = array('userName' => $username, 'password' => $password);
//1. add an extra array around params
$soapClient->__soapCall($soapFunction, array($soapFunctionParameters));
//2. or call like this:
$soapClient->$soapFunction($soapFunctionParameters);
关于PHP/SOAP : How can UserCredentials be passed to SOAP request?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17065464/
我是一名优秀的程序员,十分优秀!