0

我必须开发一个 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,anotherSoapClient 是一个扩展 PHP soapClient 类的类:PHP soapClient send custom XML

4

2 回答 2

2

为了调试您的 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();

希望它有助于调试您的代码!

于 2014-07-09T09:39:44.127 回答
1

您可能需要指定以下 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,
));
于 2014-04-18T06:31:43.210 回答