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

问题描述:

我们的要求是通过SOAP1.2发送请求。我在PHP中使用下面的代码。SOAP错误:错误代码:VersionMismatch,错误字符串:错误版本

$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错误:错误代码:VersionMismatch,错误字符串:错误的版本

如何检查它的天气要求实际使用SOAP12 ?

您可以通过检查请求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/