PHP SoapClient通过身份验证调用soap方法

时间:2012-03-13 10:25:58

标签: php web-services soap wsdl jax-ws

我正在尝试使用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 \ insoaptest.php:103堆栈跟踪:#0   [内部函数]:SoapClient-&gt; _ doRequest(' _soapCall('getDataWS',   数组)#2 {main}

但是,使用soapUI我可以连接到soapsever,并可以使用相同的凭据调用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 webservice吗?

1 个答案:

答案 0 :(得分:0)

我之前因为缓存的WSDL而遇到此错误...尝试禁用缓存:

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

有关这些设置的文档here