我必须开发一个 SOAP 客户端,供应商给我发了这个规范:
- 将通过 IP 使用 HTTPS 进行传输,并将打包为 XML 文档,以适应 XML 方案的不同定义。
- 通信是同步的,第三方应等待响应。
- 每个请求和响应都将被签名。
我正在使用PHP的soapClient类,一切正常,除了当我尝试使用我的私钥与服务器建立通信时:
Code: WSDL | Message: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://remoteserver/CustomerManagementService?wsdl' : failed to load external entity "https://remoteserver/CustomerManagementService?wsdl
然后我尝试创建一个 .pem 文件,它包含我的私钥与我的证书连接,正如我所读到的:如何在 PHP 中使用 SSL 证书发送 SOAP 请求?
但它仍然返回一个错误:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://remoteserver:80/CustomerManager/proxy/CustomerManagementService?WSDL%2FGWTCommonResources%2Fwsdl%2FGWTCommonMessages' : failed to load external entity "http://remoteserver:80/CustomerManager/proxy/CustomerManagementService?WSDL%2FGWTCommonResources%2Fwsdl%2FGWTCommonMessages
我想知道是否有某种方法可以准确获取由 PHP 的 soapClient 类发送的原始数据。以及我必须设置供应商证书的地方。
我已经尝试过使用"$client->__getLastRequest((",但我得到一个 NULL。这是我的代码:
$client = new anotherSoapClient($service, array(
'local_cert' => $pem,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'ciphers'=> "SHA1",
'verify_peer' => false,
'allow_self_signed' => true
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
),
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
));
// Test connection
echo BR.'Functions: <pre>';var_dump($client->__getFunctions());echo '</pre>';
$XMLrequest = $client->prepareRequest($email);
$response = $client->__anotherRequest('getCustomerInfo', $XMLrequest);
echo "REQUEST:'n" . $client->__getLastRequest() . "'n";
顺便说一下,我在本地机器上使用 PHP 5.4.9,服务器有 PHP 5.3.10 和另一个 SoapClient 是一个扩展 PHP soap客户端类的类:PHP soap客户端发送自定义 XML
为了调试 SOAP 请求的建议,您必须扩展 SoapClient 类。
class SoapClientDebug extends SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
// Add code to inspect/dissect/debug/adjust the XML given in $request here
// Uncomment the following line, if you actually want to do the request
// return parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
接下来在您的请求中使用它:
$client = new SoapClientDebug("x.wsdl");
$response = $client->__soapCall($function);
echo $client->__getLastRequest();
希望它有助于调试您的代码!
您可能需要指定以下 SoalClient 选项:
$defaultEndpoint = "https://remoteserver/CustomerManagementService";
$uri = "https://remoteserver";
$client = new anotherSoapClient($service, array(
'local_cert' => $pem,
'location' => $defaultEndpoint,
'uri' => $uri,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_2,
'authentication'=> SOAP_AUTHENTICATION_DIGEST,
'ssl' => array(
'ciphers'=> "SHA1",
'verify_peer' => false,
'allow_self_signed' => true
),
'https' => array(
'curl_verify_ssl_peer' => false,
'curl_verify_ssl_host' => false
),
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
));