【问题标题】:SOAP Request using PHP SoapClient使用 PHP SoapClient 的 SOAP 请求
【发布时间】:2017-05-06 17:21:38
【问题描述】:

我需要发送以下 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>

我正在尝试使用 PHP 内置的 SoapClient 类来实现这一点。当我运行以下代码时,它显示“登录失败,请检查用户名和密码”。但我非常确定用户名和密码都是正确的,因为在其他应用程序中使用了相同的值。

我认为问题出在下面的代码中。你能告诉我是什么错误吗?

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();
 }

【问题讨论】:

    标签: php soap soap-client


    【解决方案1】:

    您应该明确地使用 WSDL 到 php 生成器,该生成器仍然使用本机 SoapClient 类,例如 PackageGenerator 项目。它只是根据 WSDL 生成 PHP SDK。然后你只需要使用生成的类来构造和发送你的请求。然后响应是使用生成的类的对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多