We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,680 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

PHP SoapClient: Manipulating soap call just before it's sent

Hi

I need to manipulate a soap call before it's sent off to the soap server. Currently my soap call is constructed as follows:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.xxxxxxx.co.za/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <ns1:SubmitStringLead>
        <xmlLead xsi:type="xsd:string">
            <strXml>
                <Lead>
                    <General>
                        <dealer>419</dealer>
                        <source ref="1334923054">randomstring</source>
                        <enquiry>1</enquiry>
                        <subtype>4</subtype>
                        <comment />
                    </General>
                    <Prospect>
                        <title />
                        <name>test</name>
                        <surname />
                        <email>test@test.com</email>
                        <home />
                        <work />
                        <mobile>0123456789</mobile>
                        <idnumber />
                        <comment />
                        <area />
                        <national>true</national>
                        <license>true</license>
                    </Prospect>
                    <Item>
                        <id>1234567</id>
                        <purchaseDate>Now</purchaseDate>
                    </Item>
                </Lead>
            </strXml>
        </xmlLead>
    </ns1:SubmitStringLead>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I need it to look exactly like the following...and I can't stress "exactly" enough. The soap server is on a microsoft platform and is fussy as hell.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitStringLead xmlns="http://www.xxxxxxx.co.za/">
      <strXml>
          <Lead>
              <General>
                  <dealer>419</dealer>
                  <source ref="1334923054">randomstring</source>
                  <enquiry>1</enquiry>
                  <subtype>4</subtype>
                  <comment />
              </General>
              <Prospect>
                  <title />
                  <name>test</name>
                  <surname />
                  <email>test@test.com</email>
                  <home />
                  <work />
                  <mobile>0123456789</mobile>
                  <idnumber />
                  <comment />
                  <area />
                  <national>true</national>
                  <license>true</license>
              </Prospect>
              <Item>
                  <id>1234567</id>
                  <purchaseDate>Now</purchaseDate>
              </Item>
          </Lead>
      </strXml>
    </SubmitStringLead>
  </soap:Body>
</soap:Envelope>

Anyone help will be enormously appreciated.

2
Contributors
5
Replies
3 Days
Discussion Span
1 Year Ago
Last Updated
8
Views
Question
Answered
Venom Rush
Posting Whiz
365 posts since Oct 2007
Reputation Points: 31
Solved Threads: 3
Skill Endorsements: 0

Do you have any experience with XSLT? Since SOAP messages are actually XML documents, you can transform them with the XSLT language.

Your biggest concerns seem to be renaming elements and injecting the character data into new elements. Keywords for XSL functions are xsl:template, xsl:match and xsl:apply-templates

Try searching for a tutorial online (please avoid W3Schools).

Topi Ojala
Junior Poster in Training
66 posts since May 2009
Reputation Points: 13
Solved Threads: 20
Skill Endorsements: 0

Thanks Topi. I'll look into this.

P.S. I tend to avoid W3Schools at all costs ;)

Venom Rush
Posting Whiz
365 posts since Oct 2007
Reputation Points: 31
Solved Threads: 3
Skill Endorsements: 0

XSLT looks like something I could use but I first need to get the entire soap request (including the envelope) so that I can manipulate it.

I found a function which I thought would return everything but it only includes line 6-34 of my first example. If I can get the entire request, then altering it shouldn't be a problem.

This is the function I found:

class MSSoapClient extends SoapClient {

    function __doRequest($request, $location, $action, $version) {
        $namespace = "http://www.xxxxxxx.co.za/";

        $dom = new DOMDocument('1.0');
        $dom->loadXML($request);

        // Manipulate xml here

        $request = $dom->saveXML();

        // parent call
        return parent::__doRequest($request, $location, $action, $version);
    }
}

Does anyone know how I can get the entire soap call?

Venom Rush
Posting Whiz
365 posts since Oct 2007
Reputation Points: 31
Solved Threads: 3
Skill Endorsements: 0

So my issue has been solved. It seems that the way I was making my soap request was causing issues.

This is how I was making my soap request:

$name = 'test';
$email = 'test@test.com';
$cell = '0123456789';
$stockid = '1234567';
$ref = time();

$xmlLead = '<strXml><Lead xmlns="">
    <General>
        <dealer>419</dealer>
        <source ref="'.$ref.'">string</source>
        <enquiry>1</enquiry>
        <subtype>4</subtype>
        <comment />
    </General>
    <Prospect>
        <title />
        <name>'.$name.'</name>
        <surname />
        <email>'.$email.'</email>
        <home />
        <work />
        <mobile>'.$cell.'</mobile>
        <idnumber />
        <comment />
        <area />
        <national>true</national>
        <license>true</license>
    </Prospect>
    <Item>
        <id>'.$stockid.'</id>
        <purchaseDate>Now</purchaseDate>
    </Item>
</Lead></strXml>';

$client = new SoapClient(NULL,

        array(

        "location" => "WSDL goes here",

        'soap_version'   => SOAP_1_1,

        "style"    => SOAP_RPC,

        "trace"      => 1,

        "exceptions" => 0

           ));

print($client->__soapCall(

        /* SOAP Method Name */

        "SubmitStringLead",

        /* Parameters */

        array(

            new SoapParam(

                /* Parameter Value */

                $xmlLead,

                /* Parameter Name */

                "xmlLead"

        )),

        /* Options */

        array(

            /* SOAP Method Namespace */

            "uri" => "http://www.xxxxxxx.co.za/",

            /* SOAPAction HTTP Header for SOAP Method */

            "soapaction" => "http://www.xxxxxxx.co.za/SubmitStringLead"

        )). "\n");

And this is how I'm doing it now:

$name = 'test';
$email = 'test@test.com';
$cell = '0123456798';
$stockid = '1234567';
$ref = time();

$xmlLead = '<Lead><General><dealer>419</dealer><source ref="' . $ref . '">string</source><enquiry>1</enquiry><subtype>4</subtype><comment /></General><Prospect><title /><name>' . $name . '</name><surname /><email>' . $email . '</email><home /><work /><mobile>' . $cell . '</mobile><idnumber /><comment /><area /><national>true</national><license>true</license></Prospect><Item><id>' . $stockid . '</id><purchaseDate>Now</purchaseDate></Item></Lead>';

$client = new SoapClient('WSDL goes here', array('soap_version' => SOAP_1_1, "trace" => 1, "exceptions" => 0));

$result = $client->SubmitStringLead(array('strXml' => $xmlLead));
Venom Rush
Posting Whiz
365 posts since Oct 2007
Reputation Points: 31
Solved Threads: 3
Skill Endorsements: 0

Hopefully that helps those out there having similar issues.

Venom Rush
Posting Whiz
365 posts since Oct 2007
Reputation Points: 31
Solved Threads: 3
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Topi Ojala

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0743 seconds using 2.73MB