php – 如何定义SoapVar命名空间?

前端之家收集整理的这篇文章主要介绍了php – 如何定义SoapVar命名空间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要在我的SOAP请求中使用这个节点(使用1.1):
<CredentialsHeader xmlns="http://www.url.com/Services/P24ListingService11"
    <EMail>ricky@email.net</EMail>
    <Password>password</Password>
</CredentialsHeader>

所以我有以下PHP

$client = new SoapClient("https://exdev.www.example.com/Services/example.asmx?WSDL",array(
        "trace"      => 1,"exceptions" => 0,"cache_wsdl" => 0,'soap_version' => SOAP_1_1
        )
);

$CredentialObject = new SoapVar(array('EMail' => 'ricky@email.net','Password' => 'password'),SOAP_ENC_OBJECT);

哪个产生:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Services/Example">
    <SOAP-ENV:Header>
        <ns1:CredentialsHeader>
            <EMail>ricky@email.net</EMail>
            <Password>password</Password>
        </ns1:CredentialsHeader>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:EchoAuthenticated/>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

所有我需要做的是阻止它使用ns1,并实际上在节点中定义xmlns,如下所示:

<CredentialsHeader xmlns="http://www.example.com/Services/Example">
        <EMail>ricky@email.net</EMail>
        <Password>password</Password>
    </CredentialsHeader>

我已经在Firefox Poster中测试过,并且知道一个事实,即修改问题.

$CredentialObjectXML  = '<CredentialsHeader xmlns="http://www.example.com/Services/Example">
        <EMail>'.$UserName.'</EMail>
        <Password>'.$Password.'</Password>
    </CredentialsHeader>';


$CredentialObject  = new SoapVar($CredentialObjectXML,XSD_ANYXML);

这样,您可以直接使用XSD_ANYXML类型的XML.

希望这将解决您的问题.

猜你在找的PHP相关文章