我第一次使用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。我还尝试了这些链接Passing a PHP array in a SOAP call和Sending 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));
答案 0 :(得分: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);
答案 1 :(得分:0)
不应该这个
新的SoapHeader('http://www.example.com/','VerHeader',$ header);
是
新的SoapHeader('http://www.example.com/verifyrecord','VerHeader',$ header);
答案 2 :(得分:0)
尝试这样我将此用于我的英国邮件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);
?>