2

我在设置 SOAP 标头时遇到了两个问题。首先,我以前从未这样做过,两次,我似乎无法在这里找到一个好的解决方案。如果有完全相同的重复,我深表歉意,如果有,请指出正确的方向。

我需要在soap:Envelope 上设置以下xmlns:xsi 和xmlns:xsd 数据集。我还需要在 XML 中的第一个标签上设置一个 xmlns 属性(粗略示例)。

第一部分需要添加,当我执行 __getLastRequest() 时,第二部分已经存在。并且需要添加第三部分(只是 SendPurchases xmlns 属性)。

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">


<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
xmlns:ns1="urn:[taken out for security purposes]">


<soap:Body>
    <SendPurchases xmlns="urn:...">
    </SendPurchases>
</soap:Body>

我需要为此使用 header() 吗?我正在使用 PHP 的 SOAP 客户端。非常感谢任何帮助!

编辑:

我选择了另一条路线,不过还是感谢您的所有回答!

4

2 回答 2

4

我的信封也有类似的问题,我对此进行了修复。我将使用您提供的数据发布修复程序,您必须检查一切是否正常:

用于编辑请求的自定义类:

class CustomSoapClient extends SoapClient {

                            function __doRequest($request, $location, $action, $version) {

                                $request = str_replace('<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">', '', $request);
                                // parent call
                                return parent::__doRequest($request, $location, $action, $version);
                            }

                        }

设置肥皂客户端:

$client = new CustomSoapClient($wsdl, array(
                                'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
                                'exceptions' => true,
                                'trace' => 1,
                                'soap_version' => SOAP_1_2,
                                ));

请求:

//notice that the envelope is in the request! also you need to change the urn
$request = '
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/xmlns:ns1="urn:[taken out for security purposes]">


<soap:Body>
   <SendPurchases xmlns="urn:...">
   </SendPurchases>
</soap:Body>
</SOAP-ENV:Envelope>';

$xmlvar = new SoapVar($request, XSD_ANYXML);

$result = $client->Controleer($xmlvar);

print_r($result); // finally check the result

我希望这能帮到您 :)

于 2013-07-04T07:33:03.783 回答
1

可以在此处找到使用 PHP 的 SoapClient 正确实现的详细示例:http ://www.php.net/manual/en/soapclient.soapclient.php#97273

于 2013-07-02T13:34:02.203 回答