4

这个问题一整天都在扼杀我。

我有一个带有基本 HTTP 身份验证的客户端 Web 服务 https: //*.asmx ?WSDL..

如果我使用 SoapUI 连接到 web 服务,一切都可以完美运行,没有任何错误..

问题是当我切换到 PHP...

我设法连接到它,我可以使用 php 的 soapclient 扩展从服务器获取函数列表(我使用的是 PHP 5.3.0)。

当我尝试使用 PHP 的 soapclient 扩展调用函数时,出现以下错误:

致命错误:未捕获的 SoapFault 异常:[HTTP] Error Fetching http headers in C:\www\xpto_Atestes\soapclient.php:26 堆栈跟踪:#0 [内部函数]:>SoapClient->__doRequest(' * **... ', 'http:// * *** ...', 1, 0) #1 >C:\www\xpto_Atestes\soapclient.php(26): SoapClient->__soapCall('login', Array) #2 {main} >在第 26 行的 C:\www\xpto_Atestes\soapclient.php 中抛出

更清晰的错误(当我对调用结果进行 print_r 时):

[faultstring] => 获取 http 标头时出错
[faultcode] => HTTP

发送以下标头:

POST / * .asmx HTTP/1.1 主机:* .pt 连接:Keep-Alive 用户代理:>PHP-SOAP/5.3.0 内容类型:text/xml;charset=utf-8 SOAPAction: "http:// * * /Login" >Content-Length: 264 授权: Basic AUTHSECRETPASS

我这样称呼它:

$soapParams = array('login' => 'HTTP_LOGIN',
'password' => 'HTTP_PASS',
'authentication' => SOAP_AUTHENTICATION_BASIC,
'trace' => 1,
'exceptions' => 0
);
$client = new SoapClient("https:// * *** .asmx?WSDL", $soapParams); 回声“连接
”;$params = array('account' => '', 'msisdn'=>'NUMBER', 'password'=>'PASSWORD'); $result = $client->__soapCall("login", $params);

经过一段时间的谷歌搜索并试图找出问题所在,我切换到 nusoap .. 令我痛苦的是,它也给出了一个错误:

错误

HTTP 错误:标头的套接字读取超时

要求

POST / * * .asmx HTTP/1.0 主机:* .pt 用户代理:NuSOAP/0.9.5 (1.123) 内容类型:text/xml;charset=ISO-8859-1 SOAPAction:“http:// * *** /Login” 授权:基本 AUTHSECRETPASS 内容长度:481

数字密码

回复

我这样称呼它:

$client = new nusoap_client("https:// * * .asmx?WSDL", true);
$client->setCredentials('HTTPUSER','HTTPPASS','basic');
$params = array('account' => '', 'msisdn'=>'NUMBER', 'password'=>'PASSWORD' );
$result = $client->call('登录', $params);

使用 nusoap,我还尝试启用 curl 扩展来拨打电话:

$client->setUseCurl(true);

但没有这样的运气,它一直报错:

HTTP 错误:cURL 错误:56:从对等 url 接收数据时失败:http:// * ** * ** * ** .asmx
content_type: http_code:
0
header_size: 0
request_size: 750
filetime: -1
ssl_verify_result: 0
redirect_count:0
total_time:21.015
namelookup_time:0
connect_time: 0 pretransfer_time
:0
size_upload:462
size_download:0
speed_download:0
speed_upload:21
download_content_length:-1
upload_content_length:-1
starttransfer_time:0
redirect_time:0

我 100% 确定 web 服务没有任何问题,如果我可以从 SoapUI 调用它而没有任何问题,我不明白为什么我不能从 PHP 调用它。

我不知道我还能做些什么……我想我什么都试过了……

编辑:我刚刚尝试了另一个用于 PHP 的 Soap 类,这次来自 Zend ..

结果是:

致命错误:未捕获的 SoapFault 异常:[WSDL] SOAP-ERROR:解析 WSDL:无法从 'https:// * * .asmx?WSDL' 加载:无法加载外部实体“https:// * .asmx?WSDL ” " 在 C:\www\xpto_Atestes\Zend\Soap\Client\Common.php:51 堆栈跟踪:
#0 C:\www\xpto_Atestes\Zend\Soap\Client\Common.php(51): SoapClient->SoapClient( 'https:// * * ...', Array)
#1 C:\www** * * _Atestes\Zend\Soap\Client.php(1032): Zend_Soap_Client_Common->__construct(Array, 'https:// * * ...', Array)
#2 C:\www** ** _Atestes\Zend\Soap\Client.php(1188): Zend_Soap_Client->_initSoapClientObject()
#3 C:\www** *_Atestes\Zend\Soap\Client.php(1112): Zend_Soap_Client->getSoapClient() #4 [内部函数]: Zend_Soap_Client->__call('Login', Array)
#5 C:\www** ** _Atestes\zend .php(28): Zend_Soap_Client->Login(Array)
#6 {main} 抛出

4

1 回答 1

2

只是回答自己,以防其他人也想知道我是如何解决的。

问题如下,其中一个 Web 服务的请求 XML 必须采用以下格式:

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns123:IsTokenValid xmlns:ns123="http://www.xxxxxxx.com">
            <ns123:token xsi:type="xsd:string">'.$this->loginToken.'</ns123:token>
        </ns123:IsTokenValid>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

当我提到前缀时,我指的是 ns123 部分。问题是没有一个库生成正确的 XML 以发送到服务器,它们永远不会放置前缀,因此请求永远不会起作用。

我首先通过直接转到 NuSoap 类并更改其中一个类中的代码来解决它,但后来我发现我可以使用 NuSoap 发出自己的请求 XML,导致以下代码:

$nsValue = rand(1000, 9000);
$requestXml = '<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns'.$nsValue.':IsTokenValid xmlns:ns'.$nsValue.'="http://www.xxxxxxx.com">
<ns'.$nsValue.':token xsi:type="xsd:string">'.$this->loginToken.'</ns'.$nsValue.':token>
</ns'.$nsValue.':IsTokenValid>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$result = WebService::CallWebService($this->endPoint, 'http://www.xxxxxxx.com/IsTokenValid', $requestXml, $this->httpUser, $this->httpPass);

WebService::CallWebService 只是 NuSoap 类的包装器,它执行类似的操作(并且还具有错误处理、设置的 HTTP 身份验证等):

$client = new nusoap_client($webServiceLink, false);
$result = $client->send($request, $soapAction, '', self::$timeout, self::$responseTimeout);

伊恩和其他所有人,希望这很清楚。

于 2011-10-21T19:21:32.780 回答