[英]PHP SoapClient to call a soap method with authentication
I am trying to access a webservice (JAX-WS) with wsdl using php (5.3.5). 我正在尝试使用php(5.3.5)使用wsdl访问Web服务(JAX-WS)。 Following is the code I am using : 以下是我正在使用的代码:
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);
}
Alternatively I tried another way using the SoapHeader and supplying it while the method call. 另外,我尝试了另一种使用SoapHeader的方法,并在方法调用时提供了它。 But I am always getting the SoapFault exception : 但是我总是收到SoapFault异常:
Could not connect to host 无法连接到主机
More details exception: 更多详细信息例外:
SoapFault exception: [HTTP] Could not connect to host in C:\\wamp\\www\\SOAPTest\\client\\insoaptest.php:103 Stack trace: #0 [internal function]: SoapClient->_ doRequest(' _soapCall('getDataWS', Array) #2 {main} SoapFault例外:[HTTP]无法连接到C:\\ wamp \\ www \\ SOAPTest \\ client \\ insoaptest.php:103中的主机:堆栈跟踪:#0 [内部函数]:SoapClient-> _ doRequest(' _soapCall('getDataWS' ,数组)#2 {main}
However, using soapUI I can connect to the soapsever and can call the soapmethod with the same credentials. 但是,使用soapUI,我可以连接到soapsever,并可以使用相同的凭据调用soapmethod。 Following is some example code to access the WS - I guess it's in Java- that comes with the manual: 以下是手册随附的一些访问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
}
Can anybody please show me some light how I can access a wsdl webservice from php with authentication ? 有人可以告诉我如何通过身份验证从php访问wsdl Web服务吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.