简体   繁体   English

使用PHP SoapClient的SOAP请求

[英]SOAP Request using PHP SoapClient

I need to send the following SOAP request 我需要发送以下SOAP请求

<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. 我正在尝试使用内置于SoapClient类的PHP实现此目标。 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. 您应该最终使用WSDL来生成仍然使用本地SoapClient类(例如PackageGenerator项目)的php生成器。 It simply generates the PHP SDK according to the WSDL. 它只是根据WSDL生成PHP SDK。 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. 然后,响应是使用生成的类的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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