PHP soap request xml formatting

Given the following SOAP service:

http://www.animplant.com/rmb/rmbService?wsdl

which requires the following xml format for the getResult function:


    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header/>
    <S:Body>
        <ns2:getResult xmlns:ns2="http://rmb.animplant.com/">
            <x1>0.2</x1>
            <y1>0.2</y1>
            <x2>0.2</x2>
            <y2>0.2</y2>
            <x3>0.2</x3>
            <y3>0.2</y3>
            <x4>0.2</x4>
            <y4>0.2</y4>
            <x5>0.2</x5>
            <y5>0.2</y5>
            <x6>0.2</x6>
            <y6>0.2</y6>
            <x7>0.2</x7>
            <y7>0.2</y7>
            <x8>0.2</x8>
            <y8>0.2</y8>
            <x9>0.2</x9>
            <y9>0.2</y9>
            <x10>0.2</x10>
            <y10>0.2</y10>
            <x11>0.2</x11>
            <y11>0.2</y11>
            <x12>0.2</x12>
            <y12>0.2</y12>
            <x13>0.2</x13>
            <y13>0.2</y13>
            <x14>0.2</x14>
            <y14>0.2</y14>
           </ns2:getResult>
        </S:Body>
    </S:Envelope>

Open in new window


how would I make that request in PHP?
hbizAsked:
Who is Participating?
 
hbizAuthor Commented:
sure Ray, here's the solution:

<?php
try {
    $wsdlUrl = "http://192.168.2.8:8080/rmb/rmbService?wsdl";
    $client = new SoapClient($wsdlUrl, array('trace' => 1));
    $response = $client->getResult(array('network' =>'10', 'x1'=>0.2, 'y1'=>0.2,                                                    'x2'=>0.2, 'y2'=>0.2,  
                                                    'x3'=>0.2, 'y3'=>0.2,  
                                                    'x4'=>0.2, 'y4'=>0.2,
                                                    'x5'=>0.2, 'y5'=>0.2,
                                                    'x6'=>0.2, 'y6'=>0.2,
                                                    'x7'=>0.2, 'y7'=>0.2,
                                                    'x8'=>0.2, 'y8'=>0.2,
                                                    'x9'=>0.2, 'y9'=>0.2,
                                                    'x10'=>0.2, 'y10'=>0.2,
                                                    'x11'=>0.2, 'y11'=>0.2,
                                                    'x12'=>0.2, 'y12'=>0.2,
                                                    'x13'=>0.2, 'y13'=>0.2,
                                                    'x14'=>0.2, 'y14'=>0.2));
    $resVars = get_object_vars($response);
    echo $resVars["return"];
} catch (Exception $e) {          
        echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
    echo $e->getMessage();
}
?>
0
 
Ray PaseurCommented:
You might want to ask the service provider if they offer a REST interface.  SOAP has been abandoned by many of the major players on the WWW because it is too hard to understand and debug.  But that said, you might try using a HEREDOC string notation.

This is an untested example.  You might want to install it, run it, and use "view source" to see what comes out.
<?php 
error_reporting(E_ALL);

$str = <<<HEREDOC
    <?xml version="1.0" encoding="UTF-8"?>
    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header/>
    <S:Body>
        <ns2:getResult xmlns:ns2="http://rmb.animplant.com/">
            <x1>0.2</x1>
            <y1>0.2</y1>
            <x2>0.2</x2>
            <y2>0.2</y2>
            <x3>0.2</x3>
            <y3>0.2</y3>
            <x4>0.2</x4>
            <y4>0.2</y4>
            <x5>0.2</x5>
            <y5>0.2</y5>
            <x6>0.2</x6>
            <y6>0.2</y6>
            <x7>0.2</x7>
            <y7>0.2</y7>
            <x8>0.2</x8>
            <y8>0.2</y8>
            <x9>0.2</x9>
            <y9>0.2</y9>
            <x10>0.2</x10>
            <y10>0.2</y10>
            <x11>0.2</x11>
            <y11>0.2</y11>
            <x12>0.2</x12>
            <y12>0.2</y12>
            <x13>0.2</x13>
            <y13>0.2</y13>
            <x14>0.2</x14>
            <y14>0.2</y14>
           </ns2:getResult>
        </S:Body>
    </S:Envelope>
HEREDOC;

echo $str;

Open in new window

0
 
hbizAuthor Commented:
Thank you but how do I submit the request?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
The web service provider should give you an example of how to submit the request.  In the case of RESTful web services, the request data is usually part of the URL, in the GET arguments.

What is the web service all about?  What information or response are you expecting to get?
0
 
hbizAuthor Commented:
this was answered by the service provider.

Thanks
0
 
hbizAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for hbiz's comment http:/Q_27422037.html#37080452

for the following reason:

this was answered by the service provider
0
 
Ray PaseurCommented:
We all want to learn from the forum here at EE.  Instead of dumping the question, please post the solution you found, then accept your own answer as the solution.  That way we have an opportunity to learn from your experience.  Thanks, ~Ray
0
 
hbizAuthor Commented:
this is the solution provided by the service provider.
0
 
Ray PaseurCommented:
Excellent, thanks! ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.