【问题标题】:passing multiple WSDL header variables to SOAP server将多个 WSDL 标头变量传递给 SOAP 服务器
【发布时间】:2012-05-16 16:20:14
【问题描述】:

我是第一次使用 SOAP Web 服务,但在调用 SOAP 服务器时遇到了问题。我搜索了 WSDL SOAP 请求,但我无法解决我的问题。这是我的 WSDL 的 sn-p

<s:complexType name="VerHeader">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="HD1" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="HD2" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="HD3" type="s:string"/>
    </s:sequence>
    <s:anyAttribute/>
</s:complexType>

我必须在这些 HD1、HD2 和 HD3 变量中发送用户名、密码和一些 ID。我也试过这些链接Passing a PHP array in a SOAP callSending a Soap Header with a WSDL Soap Request with PHP

这是我尝试过但不起作用的方法,每次我运行我的代码时它都会发送失败消息,你能弄清楚我的代码或我的逻辑有什么问题吗?

$soap = new SoapClient("http://example.com/verifyrecord.asmx?WSDL");
$header = array('HD1'=>'000000023','HD2'=>'val2','HD3'=>'val2');
$header = new SoapHeader('http://www.example.com/', 'VerHeader ', $header);

$soap->__setSoapHeaders(array($header));

【问题讨论】:

  • 您收到的失败信息是什么
  • failure message 是 SOAP 服务器发送的自定义失败消息。我担心我传递的数组可能不是正确的结构,它让我由于身份验证而发送失败消息。我只想根据我的 SOAP 服务器标头验证数组的结构是否正确
  • @utta:linked question 应该回答你。此外,有时运行 Web 服务的人也做得不好,所以当您确认自己做得对时,请联系他们的技术支持。

标签: php web-services soap wsdl soap-client


【解决方案1】:

解决了这个问题。我不是通过使用php函数而是手动创建一个xml文件并将其发送到soap服务器来解决它。我已经发布了我的答案示例,以便对其他人有所帮助。谢谢大家的帮助。

// the xml to send
$xml = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <VerHeader xmlns="http://www.example.com/">
      <HD1>000000000117</HD1>
      <HD1>user</HD1>
      <HD1>password</HD1>
    </VerHeader>
  </soap:Header>
  <soap:Body>
    <m:VerifyTransaction xmlns:m="http://www.example.com/">
        <m:object1>45344</m:object1>
        <m:object2>5545437</m:object2>
    </m:VerifyTransaction>
  </soap:Body>
</soap:Envelope>';
// build your http request
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: text/xml\r\n",
'validateRequest'=>false,
'content' => $xml,
'timeout' => 10,
),
));

// send it
echo $xmlstring = file_get_contents('http://example.com/VerifyThis/VerifyThis.asmx?wsdl', false, $context); 

【讨论】:

    【解决方案2】:

    不应该这样

    new SoapHeader('http://www.example.com/', 'VerHeader', $header);

    成为

    new SoapHeader('http://www.example.com/verifyrecord', 'VerHeader', $header);

    【讨论】:

    【解决方案3】:

    尝试这样,我确实将它用于我的英国邮件 api .. 并且它有效

    <?php 
    
     $LoginWebRequest = new stdClass();
     $LoginWebRequest->Username = 'xxx cant show here xxx';
    $LoginWebRequest->Password = 'xxx cant show here xxx';
    
    //echo "<pre>";  print_r($LoginWebRequest); "</pre>"; exit;
    
    $Login = new stdClass();
    $Login->loginWebRequest = $LoginWebRequest;
    
     //echo "<pre>";  print_r($Login); "</pre>"; exit; 
    
     $soapClient = new SoapClient('https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl');
     $LoginResponse = $soapClient->Login($Login);
    
      ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多