SOAP request with attribute

前端 未结 3 967
渐次进展
渐次进展 2020-12-14 13:02

I can not seem to find out how to set an attribute to a SOAP request without using the XSD_ANYXML encoding.

The request parameter should look as fol

相关标签:
3条回答
  • 2020-12-14 13:15

    SOAP 1 does support attributes. Here is an example of Perl code using both attributes and values (from a client):

    $som = $client->call(
        'tran:getContent',
        SOAP::Header->name('cred:credentials')->attr({
            'username' => $username,
            'password' => 'xxx',
            'customerID' => 'xxx'}
        ),
        SOAP::Data->name('contentID')->value('9999')
    )
    
    0 讨论(0)
  • 2020-12-14 13:23

    For this, you need to derived the class from SoapClient and Override the method __doRequest():

    class ABRSoapClient extends SoapClient {
    
        // return xml request
        function __doRequest($request, $location, $action, $version) {
            $dom = new DOMDocument('1.0', 'UTF-8');
            $dom->preserveWhiteSpace = false;
            $xml= $dom->loadXML($request);
            // Goto request Node and Set the attribute
            $attr_ns = $dom->createAttributeNS('xmlns:ns', '' ); // instead of xmlns:ns use Namespace URL
            $attr_ns->value = '/some/ns';
            // add atribute in businessReport node 
            $dom->getElementsByTagName($report_type)->item(0)->appendChild( $attr_ns );   
            $request = $dom->saveXML();
            return parent::__doRequest($request, $location, $action, $version);
        }
    }
    
    $client = new ABRSoapClient(.....);
    $save_result = $client->request($param);
    
    // You can check the form request using function
    $client->__getLastRequest();
    

    I hope this will resolve your problem.

    0 讨论(0)
  • 2020-12-14 13:34

    SOAP does not support attributes, may be you should use REST instead!

    EDIT: Please check the body style w3c:"4.3 SOAP Body" and remember that you need to encode your message with "soap-envelope" namespace and describe your XML types thats why, you can't use attributes to describe your message data.

    But if you ask me, it can be made possible! You can use a custom SoapClient parser or something like that and convert your message as you like it. A example of that may be RSS over SOAP http://www.ibm.com/developerworks/webservices/library/ws-soaprdf. But, the problem would be that you would miss the descriptive information about your message data/types and other clients could not easy understand your messages!

    My best practice for you would be to use elements instead of attributes, i know you need to fix your XML schema but thats the way it goes or switch to a other technology.

    0 讨论(0)
提交回复
热议问题