简体   繁体   中英

SOAP Request using PHP SoapClient

I need to send the following SOAP request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:dat="http://touricoholidays.com/WSDestinations/2008/08/DataContracts">
<soapenv:Header>
  <dat:LoginHeader>
     <dat:username>myUserName</dat:username>
     <dat:password>myPassword</dat:password>
     <dat:culture>en_US</dat:culture>
     <dat:version>8</dat:version>
  </dat:LoginHeader>
</soapenv:Header>
<soapenv:Body>
  <dat:GetDestination>
     <dat:Destination>
        <dat:Continent>Europe</dat:Continent>
        <dat:Country>Spain</dat:Country>
        <dat:State></dat:State>
        <dat:City>Madrid</dat:City>
        <dat:Providers>
           <dat:ProviderType>Default</dat:ProviderType>
        </dat:Providers>

     </dat:Destination>
  </dat:GetDestination>
 </soapenv:Body>
</soapenv:Envelope>

I am trying to achieve this using PHP's built in SoapClient Class. When I run the following code it says "Login failure please check user name and password." But I am very much sure that both the username and password are correct as the same values are being used in other applications.

I think the problem is in the code below. Could you please tell me what is the mistake ?

try{

    $client     = new SoapClient($soap_url, array("trace" => 1));

    $ns = 'http://touricoholidays.com/WSDestinations/2008/08/DataContracts';
    $auth = array(
                'username' => 'myUserName',
                'password' => 'myPassword',
                'culture' => 'en_US',
                'version' => '8',
    );
    $header = new SoapHeader($ns, 'LoginHeader', $auth);
    $client->__setSoapHeaders($header);
    $res = $client->__soapCall("GetDestination", array());

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

you should definitively use a WSDL to php generator that still uses the native SoapClient class such as the PackageGenerator project. It simply generates the PHP SDK according to the WSDL. Then you only have to use the generated classes to construct and send your request. The response is then an object using the generated classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM