SOAP 设置正确的 xmlns 标头 [英] SOAP set proper xmlns headers

查看:30
本文介绍了SOAP 设置正确的 xmlns 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a two fold problem with setting SOAP headers. Primarily, I've never done it before and two, I can't seem to find a good solution on here for doing so. I apologize if there are exact duplicates, and please point me in the right direction if there are.

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

I need to set the following xmlns:xsi and xmlns:xsd data sets on the soap:Envelope. I also need to set an xmlns attribute on the first tag in the XML (rough example).

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

The first part needs to be added, the second part is already in there when I do a __getLastRequest(). And the third part needs to be added (just the SendPurchases xmlns attribute).

<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 客户端.非常感谢任何帮助!

Would I need to use the header() for this? I am using PHP's SOAP client. Any help at all is greatly appreciated!

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

I went with another route, thank you for all your answers though!

推荐答案

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

I had a simular problem with the envelope, I made a fix for that. I will post the fix with the data you provided, You will have to check if everything is oke:

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

The custom class to edit the request:

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);
                            }

                        }

设置soap客户端:

$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

希望对你有帮助:)

这篇关于SOAP 设置正确的 xmlns 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆