将多个 WSDL 标头变量传递给 SOAP 服务器


passing multiple WSDL header variables to SOAP server

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

<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。我也尝试过这些链接 在 SOAP 调用中传递 PHP 数组 和 使用 PHP 发送带有 WSDL Soap 请求的 Soap 标头

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

$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));

解决了这个问题。我不是通过使用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); 

不应该这样吗

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

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

尝试这样,我确实将其用于我的英国邮件 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);
  ?>