为什么我的 SOAP 请求不起作用?

发布于 2024-12-27 17:03:46 字数 2073 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2025-01-03 17:03:46

你只是尝试过这个吗?

error_reporting(E_ALL);
$client = new SoapClient($url,array('trace' => 1));
$client->__setSoapHeaders( new SoapHeader($url, 'SessionId', SESSION_ID) );
$result = $client->ViewTicket(array('Id'=>1355110));
var_dump($result);
echo '<hr>',str_replace('<','<',$client->__getLastRequest());

它会产生什么样的错误消息?

Did you simply try this ?

error_reporting(E_ALL);
$client = new SoapClient($url,array('trace' => 1));
$client->__setSoapHeaders( new SoapHeader($url, 'SessionId', SESSION_ID) );
$result = $client->ViewTicket(array('Id'=>1355110));
var_dump($result);
echo '<hr>',str_replace('<','<',$client->__getLastRequest());

What kind of error message does it produce ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文