PHP SoapClient调用带有身份验证的soap方法


PHP SoapClient to call a soap method with authentication

我正在尝试使用php(5.3.5)访问带有wsdl的Web服务(JAX-WS)

class insoapauth 
{ 
    public $Username; 
    public $Password; 
    public function __construct($username, $pass) 
    { 
        $this->Username = $username; 
        $this->Password = $pass; 
    } 
} 
$client = new SoapClient("http://192.168.124.11:8080/cx-subscriberdata/CXSubscriberAdmin?wsdl", array( "login" => "SOAPDW", "password" => "DW@2012"));
   // Create the header 
  $auth         = new insoapauth("SOAPDW", "DW@2012"); 
  $header       = new SoapHeader("http://192.168.124.11:8080/cx-subscriberdata/CXSubscriberAdmin", "APICredentials", $auth, false); 
try {
  $result = $client->__soapCall("getDataWS", array( 
    "CrmSearchInformation" => array( 
        "searchKeyValue"        => "93700801021"        
    ) 
)); 
  echo("<br/>Returning value of __soapCall() call: ".$result);
}catch(SoapFault $exception)
{
    print_r("Got issue:<br/>") ;
  var_dump($exception);
}

或者,我尝试了另一种方法,使用SoapHeader并在方法调用时提供它。但我总是得到SoapFault异常:

无法连接到主机

更多细节例外:

SoapFault异常:[HTTP]无法连接到中的主机C: ''wamp''www''SOAPTest''client''insaptest.php:103堆栈跟踪:#0[内部函数]:SoapClient->_doRequest('_soapCall('getDataWS',阵列)#2{main}

但是,使用soapUI,我可以连接到soapserver,并可以使用相同的凭据调用soapmethod。下面是一些访问WS的示例代码——我想它是用Java编写的——这是手册附带的:

INBeanService service = new INBeanService();
CXINWS wsPort = service.getCXINWSPort();
String username = "crmtestuser";
String password = "crmpassword";
BindingProvider bp = (BindingProvider) wsPort;
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
try {
CrmSearchInformation crmSearchInfo = new CrmSearchInformation();
crmSearchInfo.setSearchKeyValue(msisdn);
CrmSearchResult result = wsPort.getDataWS(crmSearchInfo);
//handle result
System.out.println("Result state: " + result.getSearchResultState());
} catch (NxWsException e) {
// handle exceptions
}

有人能告诉我如何通过身份验证从php访问wsdl Web服务吗?

我以前遇到过这个错误,因为缓存了WSDL。。。尝试禁用缓存:

ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);

此处的文档设置