如何使用PHP从XML创建SOAP请求
我正在尝试创建SOAP请求,但它给了我一个错误:尝试对您进行身份验证时发生异常。字符串引用未设置为字符串的实例。参数名称:s 我的代码是:如何使用PHP从XML创建SOAP请求,php,xml,soap,Php,Xml,Soap,我正在尝试创建SOAP请求,但它给了我一个错误:尝试对您进行身份验证时发生异常。字符串引用未设置为字符串的实例。参数名称:s 我的代码是: $wsdl = "https://securedwebapp.com/api/service.asmx?WSDL"; $trace = true; $exceptions = false; $debug = true; $client = new SoapClient($wsdl, array( 'trace' =>
$wsdl = "https://securedwebapp.com/api/service.asmx?WSDL";
$trace = true;
$exceptions = false;
$debug = true;
$client = new SoapClient($wsdl,
array(
'trace' => $trace,
'exceptions' => $exceptions,
'debug' => $debug,
));
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:kas="KashFlow">
<soapenv:Header/>
<soapenv:Body>
<kas:GetInvoice>
<kas:UserName>xxx</kas:UserName>
<kas:Password>xxx</kas:Password>
<kas:InvoiceNumber>184576</kas:InvoiceNumber>
</kas:GetInvoice>
</soapenv:Body>
</soapenv:Envelope>';
//var_dump($xml);
$args = array(new SoapVar($xml, XSD_ANYXML));
$res = $client->__soapCall('GetInvoice', $args);
var_dump($res);
echo "<hr>Last Request";
echo "<pre>", htmlspecialchars($client->__getLastRequest()), "</pre>";
这是一个带有简单参数的请求,但在实际情况中,我有复杂的XML请求,我不知道如何形成php对象。这就是为什么我将它作为XML发送,正如我一开始尝试做的那样 现在,强烈建议使用WSDL到PHP生成器,以避免遇到此类问题
我建议使用允许基于WSDL生成PHPSDK的项目。生成的PHP SDK包含构造请求、发送请求和仅使用OOP方法处理响应所需的所有内容。您最好使用Curl发送一个自定义的复杂SOAP XML请求。。下面是一个示例,您应该遵循规范并更改示例代码
$wsdl = 'https://securedwebapp.com/api/service.asmx?WSDL';
$trace = true;
$exceptions = false;
$debug = true;
$client = new SoapClient($wsdl,
array(
'trace' => $trace,
'exceptions' => $exceptions,
'debug' => $debug,
));
$params = array(
'InvoiceNumber' =>'81217',
'UserName' => 'xxx',
'Password' => 'xxx'
);
$resp = $client->GetInvoice($params);
print_r($resp);