SOAP Fault:故障代码:VersionMismatch,故障字符串:错误的版本

时间:2017-08-11 17:39:07

标签: php soap soap-client

我们的要求是通过SOAP1.2发送请求。我在PHP中使用下面的代码。

$basic_auth = base64_encode(USERNAME.':'.PASSWORD);
$opts = array(
    'http'=>array(
            'header' => "Authorization: Basic $basic_auth
                         x-ibm-client-id: $client_id
                         x-ibm-client-secret: $client_secret"
        )
    );
$context = stream_context_create($opts);
$soap_client = new SoapClient(WSDL, array("trace"=>1,
                                              "local_cert"=>"/var/www/cert.pem",
                                              "passphrase"=>"xxxxx",
                                              "soap_version"=>SOAP_1_2,
                                              "exeptions"=>true,
                                              "stream_context"=>$context,
                                              "location"=>LOCATION
                                              ));
try{
    $params = array(
        'getBalance' => array(
            'version' => 1,
            'partnerCode'=>PARTNER_CODE
        ));
    $post_response = $soap_client->__soapCall('getBalance', $params);
    return $post_response;
}
catch(SoapFault $fault){
    highlight_string($soap_client->__getLastRequestHeaders());
    highlight_string($soap_client->__getLastRequest());
    die("SOAP Fault: fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}

我得到的错误如下:

  

SOAP Fault:错误代码:VersionMismatch,错误字符串:错误的版本

如何检查天气请求实际上是否使用SOAP12?

1 个答案:

答案 0 :(得分:0)

您可以通过检查请求XML来检查您的SOAP请求是否使用了正确的版本。请求之后,检查XML:

var_dump($soap_client->__getLastRequest());

请注意信封声明中使用的命名空间。

SOAP 1.2:http://www.w3.org/2003/05/soap-envelope

SOAP 1.1 http://schemas.xmlsoap.org/soap/envelope/