php soap代理在Web服务操作调用中失败

时间:2016-01-07 21:17:53

标签: php soap proxy

我正在使用代理进行网络服务调用。 使用代理的SoapClient调用工作正常但使用相同的SoapClient对象调用webservice函数失败。当我问服务器的人时,他们说他们可以看到第一个GET呼叫而不是POST呼叫。

以下是代码:

$context = stream_context_create(
array(
    'ssl' => array( 'SNI_enabled' => false, 'SNI_server_name' => $domain
    ),
    'http' => array(
        'proxy' => 'proxyurl:8080'
    )
)
);

$soapOptions = array(
    'trace' => true,
    'stream_context' => $context
);


try {
    $client = new SoapClient(WSDL_URL, $soapOptions);
}  catch (SoapFault $fault) {
    echo "SOAP Fault: (faultcode: {".$fault->faultcode."}, faultstring: {".$fault->faultstring."})", E_USER_ERROR;
} catch (Exception $e) {
    echo "SOAP Exception: (faultcode: {".$fault->faultcode."}, faultstring: {".$fault->faultstring."})", E_USER_ERROR;
}

echo "Calling Grant Role";
echo "<hr>";

$userName = "username";
$roleIdFromUser = "userrole";

try {
    $result = $client->GrantAffiliateUserRole(array('affiliateId' => AFFILIATEID, 'password' => AFFILIATEPASSWORD, 'username' => $userName, 'roleId' => $roleIdFromUser));
    echo "Success";
}  catch (SoapFault $fault) {
    echo "SOAP Proxy Fault: (faultcode: {".$fault->faultcode."}, faultstring: {".$fault->faultstring."})", E_USER_ERROR;
    echo "Failed Grant Fault";
} catch (Exception $e) {
    echo "SOAP Exception: (faultcode: {".$fault->faultcode."}, faultstring: {".$fault->faultstring."})", E_USER_ERROR;
    echo "Failed Grant Exception";
}

输出结果为:

object(SoapClient)#1 (4) { ["trace"]=> int(1) ["_stream_context"]=> resource(2) of type (stream-context) ["_soap_version"]=> int(1) ["sdl"]=> resource(4) of type (Unknown) } 

Calling Grant Role

SOAP Proxy Fault: (faultcode: {HTTP}, faultstring: {Could not connect to host})256

Failed Grant Fault

同样,webservice动作调用不识别用于为WSDL.Any帮助进行SoapClient调用的代理?

1 个答案:

答案 0 :(得分:1)

我已经解决了这个问题。由于Web服务URL是HTTPS,因此SSL只需要是流上下文,并将其与Proxy数组一起传递给WSDL调用,如下所示。

$context = stream_context_create(
array(
    'ssl' => array('SNI_enabled' => false)
    )
);

$soapOptions = array('proxy_host' => PROXY_HOST, 'proxy_port' => PROXY_PORT, 'stream_context' => $context);

$client = new SoapClient(WSDL_URL, $soapOptions);