为什么我的 SOAP 请求不起作用?
我正在尝试使用 PHP 发出 SOAP 请求。我的请求似乎与 SOAP 服务器文档中详细说明的请求匹配(但方法略有不同),但我收到身份验证错误,就好像未包含标头一样。
文档的请求示例
<?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>
<AuthHeader xmlns="http://novosolutions.com/">
<SessionId>string</SessionId>
</AuthHeader>
</soap:Header>
<soap:Body>
<ViewTicket xmlns="http://novosolutions.com/">
<Id>int</Id>
</ViewTicket>
</soap:Body>
</soap:Envelope>
我的 PHP 代码输出的请求:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://novosolutions.com/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<SessionId>623</SessionId>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ViewTicket>
<Id>1355110</Id>
</ns1:ViewTicket>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的 PHP 代码相当简单。我做错了什么吗?
$url = URL_BASE . URL_TICKET . '?WSDL';
$soapStruct = new SoapVar(array('SessionId' => SESSION_ID), SOAP_ENC_OBJECT);
$header = new SoapHeader('http://novosolutions.com/', 'AuthHeader', $soapStruct, false);
try {
$client = new SoapClient($url, array('trace' => 1));
}
catch (SoapFault $exception) {
echo 'Exception='.$exception;
}
$client->__setSoapHeaders(array($header));
var_dump($client);
$soapData = new SoapVar(array('Id' => 1355110), SOAP_ENC_OBJECT);
$result = $client->__soapCall('ViewTicket', array('parameters' => $soapData));
var_dump($result);
echo $client->__getLastRequest();
编辑: 通过使用curl 测试请求,我将范围缩小到PHP 的SoapClient 使用命名空间的变量这一事实。不被 SoapServer 接受,但是被接受。现在我只需要弄清楚如何防止 SoapClient 使用变量。
I am trying to make a SOAP request with PHP. It seems my request matches the request detailed in the SOAP server's documentation (but with slightly different methods), yet I'm getting an authentication error, as if the header is not being included.
The documentation's request sample
<?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>
<AuthHeader xmlns="http://novosolutions.com/">
<SessionId>string</SessionId>
</AuthHeader>
</soap:Header>
<soap:Body>
<ViewTicket xmlns="http://novosolutions.com/">
<Id>int</Id>
</ViewTicket>
</soap:Body>
</soap:Envelope>
The request my PHP code outputs:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://novosolutions.com/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<SessionId>623</SessionId>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ViewTicket>
<Id>1355110</Id>
</ns1:ViewTicket>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
My PHP code is rather simple. Am I doing something wrong?
$url = URL_BASE . URL_TICKET . '?WSDL';
$soapStruct = new SoapVar(array('SessionId' => SESSION_ID), SOAP_ENC_OBJECT);
$header = new SoapHeader('http://novosolutions.com/', 'AuthHeader', $soapStruct, false);
try {
$client = new SoapClient($url, array('trace' => 1));
}
catch (SoapFault $exception) {
echo 'Exception='.$exception;
}
$client->__setSoapHeaders(array($header));
var_dump($client);
$soapData = new SoapVar(array('Id' => 1355110), SOAP_ENC_OBJECT);
$result = $client->__soapCall('ViewTicket', array('parameters' => $soapData));
var_dump($result);
echo $client->__getLastRequest();
EDIT:
By testing the request with a curl, I've narrowed it down to the fact that PHP's SoapClient uses a variable for the namespace. is not accepted by the SoapServer, but is. Now I just need to figure out how to prevent SoapClient from using variables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你只是尝试过这个吗?
它会产生什么样的错误消息?
Did you simply try this ?
What kind of error message does it produce ?