我正在嘗試使用 PHP 肥皂客戶端訪問 WCF 服務。我不斷收到錯誤訊息:“錯誤獲取 http 標頭”我也嘗試增加 default_socket_time。訪問服務時,我需要使用基本身份驗證以及方法引數。以下是我的 PHP 代碼。我無法更改服務器配置。
<?php
$wsdl = "https://example.com/NewServer/Services/WCFServices.svc?wsdl";
$url=$wsdl;
$svc = 'WCFServices';
$func = 'getValId';
$username = "admin";
$password = "admin";
$apiauth =array('UserName'=>$username,'Password'=>$password);
$authHeader = new SoapHeader('https://tempuri.org/', 'AuthHeader', $apiauth);
$client = new SoapClient($url, array('soap_version' => SOAP_1_2,
'exceptions' => true,
'trace' => true);
try
{
ini_set('default_socket_timeout', 600);
$client->__setSoapHeaders($authHeader);
$info = $client->__soapCall($func, array('extRef' => 'ABCD'));
var_dump($info);
}
catch (SoapFault $fault)
{
var_dump($fault);
$xml=$fault->faultstring;
die;
}
?>
正確路徑的指導將不勝感激。
uj5u.com熱心網友回復:
我正在呼叫的 WCF 服務具有可用的 HTTP 和基本系結。所以我呼叫了使用 SOAP 1.1 版本的基本端點。發布代碼,因為它對將來的某人有用。
<?php
class WsseAuthHeader extends SoapHeader
{
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
function __construct($user, $pass, $ns = null)
{
if ($ns)
{
$this->wss_ns = $ns;
}
$auth = new stdClass();
$auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
$security_sv = new SoapVar(
new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
}
$options = array(
'soap_version' => SOAP_1_1,
'exceptions' => true,
'trace' => 1,
'wdsl_local_copy' => true);
$username = "username";
$password = "password";
$wsse_header = new WsseAuthHeader($username, $password);
$client = new SoapClient('https://ServerName/WCFService.svc?wsdl', $options);
$client->__setSoapHeaders(array($wsse_header));
$client->__setLocation('https://ServerName/WCFService.svc/basicSecurity');
try
{
$params = array('param1' => 'xxxx');
$phpresponse = $client->__soapCall('methodname', array('parameters' => $params));
var_dump($phpresponse);
echo "</b><BR/><BR/>";
}
catch(Exception $e)
{
echo "<h2>Exception Error!</h2></b>";
echo $e->getMessage();
}
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/522785.html
標籤:phpwcf肥皂1.2
