How to define a SoapVar namespace?

前端 未结 3 1695
情话喂你
情话喂你 2021-02-14 10:14

I need to have this node in my SOAP Request (using 1.1):

ricky@e         


        
相关标签:
3条回答
  • 2021-02-14 10:32
    $CredentialObjectXML  = '<CredentialsHeader xmlns="http://www.example.com/Services/Example">
            <EMail>'.$UserName.'</EMail>
            <Password>'.$Password.'</Password>
        </CredentialsHeader>';
    
    
    $CredentialObject  = new SoapVar($CredentialObjectXML,XSD_ANYXML);
    

    This way you can directly use the XML with Type XSD_ANYXML.

    Hope this will resolve your problem.

    0 讨论(0)
  • 2021-02-14 10:37

    http://www.php.net/manual/tr/soapvar.soapvar.php

    Parameter "node_namespace" is what you've been looking for i guess.

    0 讨论(0)
  • 2021-02-14 10:41

    I had the same problem and found out that if you map a dummy class to the credential complex type from your WSDL, PHP will output something like:

    <?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>
                <ns1:EMail>ricky@email.net</ns1:EMail>
                <ns1:Password>password</ns1:Password>
            </ns1:CredentialsHeader>
        </SOAP-ENV:Header>
        <SOAP-ENV:Body>
            <ns1:EchoAuthenticated/>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    This is not exactly what was requested but although more verbose, it is equivalent.

    The code goes like this:

    $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,
            "classmap"      => array(
                'credential_complex_type'   => 'CredentialObject',
            ),
        )
    );
    
    class CredentialObject {}
    
    $credentialObject = new CredentialObject();
    $credentialObject->Email = 'ricky@email.net';
    $credentialObject->Password = 'password';
    
    0 讨论(0)
提交回复
热议问题