我正在尝试使用php(5.3.5)使用wsdl访问webservice(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("
Returning value of __soapCall() call: ".$result);
}catch(SoapFault $exception)
{
print_r("Got issue:
") ;
var_dump($exception);
}
或者,我尝试使用SoapHeader的另一种方式,并在方法调用时提供它 . 但我总是得到SoapFault异常:
无法连接到主机
更多细节例外:
SoapFault异常:[HTTP]无法连接到C:\ wamp \ www \ SOAPTest \ client \ insoaptest.php中的主机:103堆栈跟踪:#0 [内部函数]:SoapClient - > _ doRequest('_ soapCall('getDataWS') ,数组)#2
但是,使用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 回答
我之前因为缓存的WSDL而遇到此错误...尝试禁用缓存:
有关这些设置的文档here