Creating a SOAP call using PHP with an XML body

前端 未结 2 1937
旧巷少年郎
旧巷少年郎 2020-12-04 10:27

I\'m trying to call a SOAP method using PHP.

Here\'s the code I\'ve got:

$data = array(\'Acquirer\' =>
  array(
    \'Id\' => \'MyId\',
    \'U         


        
2条回答
  •  甜味超标
    2020-12-04 10:59

    There are a couple of ways to solve this. The least hackiest and almost what you want:

    $client = new SoapClient(
        null,
        array(
            'location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
            'uri' => 'http://example.com/wsdl',
            'trace' => 1,
            'use' => SOAP_LITERAL,
        )
    );
    $params = new \SoapVar("MyIdMyUserIdMyPassword", XSD_ANYXML);
    $result = $client->Echo($params);
    

    This gets you the following XML:

    
    
        
            
                
                    MyId
                    MyUserId
                    MyPassword
                
            
        
    
    

    That is almost exactly what you want, except for the namespace on the method name. I don't know if this is a problem. If so, you can hack it even further. You could put the tag in the XML string by hand and have the SoapClient not set the method by adding 'style' => SOAP_DOCUMENT, to the options array like this:

    $client = new SoapClient(
        null,
        array(
            'location' => 'https://example.com/ExampleWebServiceDL/services/ExampleHandler',
            'uri' => 'http://example.com/wsdl',
            'trace' => 1,
            'use' => SOAP_LITERAL,
            'style' => SOAP_DOCUMENT,
        )
    );
    $params = new \SoapVar("MyIdMyUserIdMyPassword", XSD_ANYXML);
    $result = $client->MethodNameIsIgnored($params);
    

    This results in the following request XML:

    
        
            
                
                    MyId
                    MyUserId
                    MyPassword
                
            
        
    
    

    Finally, if you want to play around with SoapVar and SoapParam objects, you can find a good reference in this comment in the PHP manual: http://www.php.net/manual/en/soapvar.soapvar.php#104065. If you get that to work, please let me know, I failed miserably.

提交回复
热议问题