Erro SOAP no PHP: OperationFormatter encontrou um corpo de mensagem inválido

Pergunta original:

Estou tentando obter dados deSOAP API wsdl ligação. Meu código como abaixo. Mas eu recebo esse erro. Alguém por favor pode ajudar com isso?

Mensagem de erro: OperationFormatter encontrou um corpo de mensagem inválido. Espera-se encontrar o tipo de nó 'Elemento' com o nome 'GetLocalRates' e o espaço para nome 'http://tempuri.org/' Tipo de nó encontrado 'Elemento' com o nome 'soapenv: Envelope' e espaço para nome 'http://www.w3.org/2003/05/soap-envelope'

<?php
$api_link = 'https://www.my-api-link.com/RateAPI.svc/SSL?wsdl';

//setting xml request to api
$request = '<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" xmlns:ezr="http://schemas.datacontract.org/2004/07/EzremitAPI.Entities">
              <soapenv:Body>
                 <tem:GetLocalRates>
                     <tem:credentials>
                         <ezr:AgentCode>####</ezr:AgentCode>
                         <ezr:HashedPassword>####</ezr:HashedPassword>
                         <ezr:Username>####</ezr:Username>
                     </tem:credentials>
                     <tem:payincurcode>####</tem:payincurcode>
                     <tem:transferType>####</tem:transferType>
                 </tem:GetLocalRates>
              </soapenv:Body>
            </soapenv:Envelope>';

try {
$client = new SoapClient($api_link, array('cache_wsdl' => WSDL_CACHE_NONE, 'soap_version' => SOAP_1_2, 'reliable' => 1.2 , 'useWSA' => TRUE ) );
$soapaction = "http://tempuri.org/IRateAPI/GetLocalRates";
$client->soap_defencoding = 'UTF-8';
// Apply WSA headers
$headers = array();
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://www.my-api-link.com/RateAPI.svc/SSL?wsdl', true);
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'http://tempuri.org/IRateAPI/GetLocalRates', true);
$client->__setSoapHeaders($headers);

$response = $client->GetLocalRates(new SoapVar($request, XSD_ANYXML));
print_r($response);

}
  catch(Exception $e) {
    echo $e->getMessage();
}
?>

Editar 1 (código alterado conforme o primeiro comentário)

Resultados:

http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/faults:Receivera:InternalServiceFaultOperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetLocalRates' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'soapenv:Envelope' and namespace 'http://www.w3.org/2003/05/soap-envelope'OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetLocalRates' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'soapenv:Envelope' and namespace 'http://www.w3.org/2003/05/soap-envelope' at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
 at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
 at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
 at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
 at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)System.Runtime.Serialization.SerializationException

Edição 2:

$ client -> __ getTypes () Resultados:

array(8) {
  [0]=>
  string(84) "struct EzCredential {
 string AgentCode;
 string HashedPassword;
 string Username;
}"
  [1]=>
  string(58) "struct ArrayOfCurrencyRate {
 CurrencyRate CurrencyRate;
}"
  [2]=>
  string(187) "struct CurrencyRate {
 decimal AgentMargin;
 string CurrencyCode;
 string CurrencyDescription;
 decimal FromAmount;
 decimal Rate;
 string RateType;
 decimal ToAmount;
 string Trantype;
}"
  [3]=>
  string(95) "struct GetLocalRates {
 EzCredential credentials;
 string payincurcode;
 string transferType;
}"
  [4]=>
  string(74) "struct GetLocalRatesResponse {
 ArrayOfCurrencyRate GetLocalRatesResult;
}"
  [5]=>
  string(8) "int char"
  [6]=>
  string(17) "duration duration"
  [7]=>
  string(11) "string guid"
}

$ client -> __ getFunctions () Resultados:

array(1) {
  [0]=>
  string(62) "GetLocalRatesResponse GetLocalRates(GetLocalRates $parameters)"
}

Corrigido: Usado abaixo, em vez do envelope XML. Muito obrigado, @Marcel. Você é um grande salvador.

$requestParams = array( 'credentials' => array('AgentCode' => $acode,
                                               'HashedPassword' => $hpass,
                                               'Username' => $uname),
                  'payincurcode' => $ccode,
                  'transferType' => $ttype
              );

$response = $client->GetLocalRates( $requestParams );

questionAnswers(1)

yourAnswerToTheQuestion