Using Guzzle to consume SOAP












17















I'm loving the Guzzle framework that I just discovered. I'm using it to aggregate data across multiple API's using different response structures. It's worked find with JSON and XML, but one the services i need to consume uses SOAP. Is there a built-in way to consume SOAP services with Guzzle?










share|improve this question























  • I also would like to get more info on this topic. The Guzzle documentation does not mention anything about .wsdl files or SOAP.

    – Rvanlaak
    Oct 7 '13 at 12:18
















17















I'm loving the Guzzle framework that I just discovered. I'm using it to aggregate data across multiple API's using different response structures. It's worked find with JSON and XML, but one the services i need to consume uses SOAP. Is there a built-in way to consume SOAP services with Guzzle?










share|improve this question























  • I also would like to get more info on this topic. The Guzzle documentation does not mention anything about .wsdl files or SOAP.

    – Rvanlaak
    Oct 7 '13 at 12:18














17












17








17


3






I'm loving the Guzzle framework that I just discovered. I'm using it to aggregate data across multiple API's using different response structures. It's worked find with JSON and XML, but one the services i need to consume uses SOAP. Is there a built-in way to consume SOAP services with Guzzle?










share|improve this question














I'm loving the Guzzle framework that I just discovered. I'm using it to aggregate data across multiple API's using different response structures. It's worked find with JSON and XML, but one the services i need to consume uses SOAP. Is there a built-in way to consume SOAP services with Guzzle?







soap guzzle






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 3 '13 at 23:35









LordZardeckLordZardeck

3,6391549105




3,6391549105













  • I also would like to get more info on this topic. The Guzzle documentation does not mention anything about .wsdl files or SOAP.

    – Rvanlaak
    Oct 7 '13 at 12:18



















  • I also would like to get more info on this topic. The Guzzle documentation does not mention anything about .wsdl files or SOAP.

    – Rvanlaak
    Oct 7 '13 at 12:18

















I also would like to get more info on this topic. The Guzzle documentation does not mention anything about .wsdl files or SOAP.

– Rvanlaak
Oct 7 '13 at 12:18





I also would like to get more info on this topic. The Guzzle documentation does not mention anything about .wsdl files or SOAP.

– Rvanlaak
Oct 7 '13 at 12:18












4 Answers
4






active

oldest

votes


















6














You can get Guzzle to send SOAP requests.
Note that SOAP always has an Envelope, Header and Body.



<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/">
<soapenv:Header/>
<soapenv:Body>
<NormalXmlGoesHere>
<Data>Test</Data>
</NormalXmlGoesHere>
</soapenv:Body>


The first thing I do is build the xml body with SimpleXML:



$xml = new SimpleXMLElement('<NormalXmlGoesHere xmlns="https://api.xyz.com/DataService/"></NormalXmlGoesHere>');
$xml->addChild('Data', 'Test');

// Removing xml declaration node
$customXML = new SimpleXMLElement($xml->asXML());
$dom = dom_import_simplexml($customXML);
$cleanXml = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);


We then wrap our xml body with the soap envelope, header and body.



$soapHeader = '<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>';

$soapFooter = '</soapenv:Body></soapenv:Envelope>';

$xmlRequest = $soapheader . $cleanXml . $soapFooter; // Full SOAP Request


We then need to find out what our endpoint is in the api docs.



We then build the client in Guzzle:



$client = new Client([
'base_url' => 'https://api.xyz.com',
]);

try {
$response = $client->post(
'/DataServiceEndpoint.svc',
[
'body' => $xmlRequest,
'headers' => [
'Content-Type' => 'text/xml',
'SOAPAction' => 'https://api.xyz.com/DataService/PostData' // SOAP Method to post to
]
]
);

var_dump($response);
} catch (Exception $e) {
echo 'Exception:' . $e->getMessage();
}

if ($response->getStatusCode() === 200) {
// Success!
$xmlResponse = simplexml_load_string($response->getBody()); // Convert response into object for easier parsing
} else {
echo 'Response Failure !!!';
}





share|improve this answer































    4














    IMHO Guzzle doesn't have full SOAP support and works only with HTTP requests.
    src/Guzzle/Http/ClientInterface.php Line:76



    public function createRequest(                                              
    $method = RequestInterface::GET,
    $uri = null,
    $headers = null,
    $body = null,
    array $options = array()
    );


    Even if SOAP server is configured to negotiate on port 80 I think php SoapClient is more appropriate solution here as it supports WSDL






    share|improve this answer
























    • I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

      – gmponos
      Sep 3 '15 at 5:42



















    4














    Old Topic, but as I was searching for the same answer, it seems async-soap-guzzle is doing the job.






    share|improve this answer































      1














      Guzzle HTTP can be used for SOAP requests & works like a charm:



      Below is the way I have implemented.



      Create variables:



          public function __construct(Request $request) {
      $this->request = $request;
      $this->openSoapEnvelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">';
      $this->soapHeader = '<soap:Header>
      <tem:Authenticate>
      <-- any header data goes here-->
      </tem:Authenticate>
      </soap:Header>';

      $this->closeSoapEnvelope = '</soap:Envelope>';
      }


      Create a function to form a soap request.



      public function generateSoapRequest($soapBody){
      return $this->openSoapEnvelope . $this->soapHeader . $soapBody . $this->closeSoapEnvelope;
      }


      Define a body & call generateSoapRequest method.
      e.g:



      $soapBody           =   '<soap:Body>
      <tem:GetSomeDetails/>
      </soap:Body>';

      $xmlRequest = $this->generateSoapRequest($soapBody);


      $client = new Client();

      $options = [
      'body' => $xmlRequest,
      'headers' => [
      "Content-Type" => "text/xml",
      "accept" => "*/*",
      "accept-encoding" => "gzip, deflate"
      ]
      ];

      $res = $client->request(
      'POST',
      'http://your-soap-endpoint-url',
      $options
      );

      print_r($res->getBody());





      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19170846%2fusing-guzzle-to-consume-soap%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6














        You can get Guzzle to send SOAP requests.
        Note that SOAP always has an Envelope, Header and Body.



        <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/">
        <soapenv:Header/>
        <soapenv:Body>
        <NormalXmlGoesHere>
        <Data>Test</Data>
        </NormalXmlGoesHere>
        </soapenv:Body>


        The first thing I do is build the xml body with SimpleXML:



        $xml = new SimpleXMLElement('<NormalXmlGoesHere xmlns="https://api.xyz.com/DataService/"></NormalXmlGoesHere>');
        $xml->addChild('Data', 'Test');

        // Removing xml declaration node
        $customXML = new SimpleXMLElement($xml->asXML());
        $dom = dom_import_simplexml($customXML);
        $cleanXml = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);


        We then wrap our xml body with the soap envelope, header and body.



        $soapHeader = '<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>';

        $soapFooter = '</soapenv:Body></soapenv:Envelope>';

        $xmlRequest = $soapheader . $cleanXml . $soapFooter; // Full SOAP Request


        We then need to find out what our endpoint is in the api docs.



        We then build the client in Guzzle:



        $client = new Client([
        'base_url' => 'https://api.xyz.com',
        ]);

        try {
        $response = $client->post(
        '/DataServiceEndpoint.svc',
        [
        'body' => $xmlRequest,
        'headers' => [
        'Content-Type' => 'text/xml',
        'SOAPAction' => 'https://api.xyz.com/DataService/PostData' // SOAP Method to post to
        ]
        ]
        );

        var_dump($response);
        } catch (Exception $e) {
        echo 'Exception:' . $e->getMessage();
        }

        if ($response->getStatusCode() === 200) {
        // Success!
        $xmlResponse = simplexml_load_string($response->getBody()); // Convert response into object for easier parsing
        } else {
        echo 'Response Failure !!!';
        }





        share|improve this answer




























          6














          You can get Guzzle to send SOAP requests.
          Note that SOAP always has an Envelope, Header and Body.



          <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/">
          <soapenv:Header/>
          <soapenv:Body>
          <NormalXmlGoesHere>
          <Data>Test</Data>
          </NormalXmlGoesHere>
          </soapenv:Body>


          The first thing I do is build the xml body with SimpleXML:



          $xml = new SimpleXMLElement('<NormalXmlGoesHere xmlns="https://api.xyz.com/DataService/"></NormalXmlGoesHere>');
          $xml->addChild('Data', 'Test');

          // Removing xml declaration node
          $customXML = new SimpleXMLElement($xml->asXML());
          $dom = dom_import_simplexml($customXML);
          $cleanXml = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);


          We then wrap our xml body with the soap envelope, header and body.



          $soapHeader = '<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>';

          $soapFooter = '</soapenv:Body></soapenv:Envelope>';

          $xmlRequest = $soapheader . $cleanXml . $soapFooter; // Full SOAP Request


          We then need to find out what our endpoint is in the api docs.



          We then build the client in Guzzle:



          $client = new Client([
          'base_url' => 'https://api.xyz.com',
          ]);

          try {
          $response = $client->post(
          '/DataServiceEndpoint.svc',
          [
          'body' => $xmlRequest,
          'headers' => [
          'Content-Type' => 'text/xml',
          'SOAPAction' => 'https://api.xyz.com/DataService/PostData' // SOAP Method to post to
          ]
          ]
          );

          var_dump($response);
          } catch (Exception $e) {
          echo 'Exception:' . $e->getMessage();
          }

          if ($response->getStatusCode() === 200) {
          // Success!
          $xmlResponse = simplexml_load_string($response->getBody()); // Convert response into object for easier parsing
          } else {
          echo 'Response Failure !!!';
          }





          share|improve this answer


























            6












            6








            6







            You can get Guzzle to send SOAP requests.
            Note that SOAP always has an Envelope, Header and Body.



            <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/">
            <soapenv:Header/>
            <soapenv:Body>
            <NormalXmlGoesHere>
            <Data>Test</Data>
            </NormalXmlGoesHere>
            </soapenv:Body>


            The first thing I do is build the xml body with SimpleXML:



            $xml = new SimpleXMLElement('<NormalXmlGoesHere xmlns="https://api.xyz.com/DataService/"></NormalXmlGoesHere>');
            $xml->addChild('Data', 'Test');

            // Removing xml declaration node
            $customXML = new SimpleXMLElement($xml->asXML());
            $dom = dom_import_simplexml($customXML);
            $cleanXml = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);


            We then wrap our xml body with the soap envelope, header and body.



            $soapHeader = '<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>';

            $soapFooter = '</soapenv:Body></soapenv:Envelope>';

            $xmlRequest = $soapheader . $cleanXml . $soapFooter; // Full SOAP Request


            We then need to find out what our endpoint is in the api docs.



            We then build the client in Guzzle:



            $client = new Client([
            'base_url' => 'https://api.xyz.com',
            ]);

            try {
            $response = $client->post(
            '/DataServiceEndpoint.svc',
            [
            'body' => $xmlRequest,
            'headers' => [
            'Content-Type' => 'text/xml',
            'SOAPAction' => 'https://api.xyz.com/DataService/PostData' // SOAP Method to post to
            ]
            ]
            );

            var_dump($response);
            } catch (Exception $e) {
            echo 'Exception:' . $e->getMessage();
            }

            if ($response->getStatusCode() === 200) {
            // Success!
            $xmlResponse = simplexml_load_string($response->getBody()); // Convert response into object for easier parsing
            } else {
            echo 'Response Failure !!!';
            }





            share|improve this answer













            You can get Guzzle to send SOAP requests.
            Note that SOAP always has an Envelope, Header and Body.



            <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/">
            <soapenv:Header/>
            <soapenv:Body>
            <NormalXmlGoesHere>
            <Data>Test</Data>
            </NormalXmlGoesHere>
            </soapenv:Body>


            The first thing I do is build the xml body with SimpleXML:



            $xml = new SimpleXMLElement('<NormalXmlGoesHere xmlns="https://api.xyz.com/DataService/"></NormalXmlGoesHere>');
            $xml->addChild('Data', 'Test');

            // Removing xml declaration node
            $customXML = new SimpleXMLElement($xml->asXML());
            $dom = dom_import_simplexml($customXML);
            $cleanXml = $dom->ownerDocument->saveXML($dom->ownerDocument->documentElement);


            We then wrap our xml body with the soap envelope, header and body.



            $soapHeader = '<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>';

            $soapFooter = '</soapenv:Body></soapenv:Envelope>';

            $xmlRequest = $soapheader . $cleanXml . $soapFooter; // Full SOAP Request


            We then need to find out what our endpoint is in the api docs.



            We then build the client in Guzzle:



            $client = new Client([
            'base_url' => 'https://api.xyz.com',
            ]);

            try {
            $response = $client->post(
            '/DataServiceEndpoint.svc',
            [
            'body' => $xmlRequest,
            'headers' => [
            'Content-Type' => 'text/xml',
            'SOAPAction' => 'https://api.xyz.com/DataService/PostData' // SOAP Method to post to
            ]
            ]
            );

            var_dump($response);
            } catch (Exception $e) {
            echo 'Exception:' . $e->getMessage();
            }

            if ($response->getStatusCode() === 200) {
            // Success!
            $xmlResponse = simplexml_load_string($response->getBody()); // Convert response into object for easier parsing
            } else {
            echo 'Response Failure !!!';
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 14 '17 at 2:40









            acnc111acnc111

            19017




            19017

























                4














                IMHO Guzzle doesn't have full SOAP support and works only with HTTP requests.
                src/Guzzle/Http/ClientInterface.php Line:76



                public function createRequest(                                              
                $method = RequestInterface::GET,
                $uri = null,
                $headers = null,
                $body = null,
                array $options = array()
                );


                Even if SOAP server is configured to negotiate on port 80 I think php SoapClient is more appropriate solution here as it supports WSDL






                share|improve this answer
























                • I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

                  – gmponos
                  Sep 3 '15 at 5:42
















                4














                IMHO Guzzle doesn't have full SOAP support and works only with HTTP requests.
                src/Guzzle/Http/ClientInterface.php Line:76



                public function createRequest(                                              
                $method = RequestInterface::GET,
                $uri = null,
                $headers = null,
                $body = null,
                array $options = array()
                );


                Even if SOAP server is configured to negotiate on port 80 I think php SoapClient is more appropriate solution here as it supports WSDL






                share|improve this answer
























                • I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

                  – gmponos
                  Sep 3 '15 at 5:42














                4












                4








                4







                IMHO Guzzle doesn't have full SOAP support and works only with HTTP requests.
                src/Guzzle/Http/ClientInterface.php Line:76



                public function createRequest(                                              
                $method = RequestInterface::GET,
                $uri = null,
                $headers = null,
                $body = null,
                array $options = array()
                );


                Even if SOAP server is configured to negotiate on port 80 I think php SoapClient is more appropriate solution here as it supports WSDL






                share|improve this answer













                IMHO Guzzle doesn't have full SOAP support and works only with HTTP requests.
                src/Guzzle/Http/ClientInterface.php Line:76



                public function createRequest(                                              
                $method = RequestInterface::GET,
                $uri = null,
                $headers = null,
                $body = null,
                array $options = array()
                );


                Even if SOAP server is configured to negotiate on port 80 I think php SoapClient is more appropriate solution here as it supports WSDL







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 13 '14 at 6:59









                ishenkoyvishenkoyv

                60949




                60949













                • I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

                  – gmponos
                  Sep 3 '15 at 5:42



















                • I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

                  – gmponos
                  Sep 3 '15 at 5:42

















                I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

                – gmponos
                Sep 3 '15 at 5:42





                I think guzzle now is at version 6. Do you know if they did any changes to support SOAP?

                – gmponos
                Sep 3 '15 at 5:42











                4














                Old Topic, but as I was searching for the same answer, it seems async-soap-guzzle is doing the job.






                share|improve this answer




























                  4














                  Old Topic, but as I was searching for the same answer, it seems async-soap-guzzle is doing the job.






                  share|improve this answer


























                    4












                    4








                    4







                    Old Topic, but as I was searching for the same answer, it seems async-soap-guzzle is doing the job.






                    share|improve this answer













                    Old Topic, but as I was searching for the same answer, it seems async-soap-guzzle is doing the job.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 31 '16 at 8:24









                    Raphael1pxRaphael1px

                    5114




                    5114























                        1














                        Guzzle HTTP can be used for SOAP requests & works like a charm:



                        Below is the way I have implemented.



                        Create variables:



                            public function __construct(Request $request) {
                        $this->request = $request;
                        $this->openSoapEnvelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">';
                        $this->soapHeader = '<soap:Header>
                        <tem:Authenticate>
                        <-- any header data goes here-->
                        </tem:Authenticate>
                        </soap:Header>';

                        $this->closeSoapEnvelope = '</soap:Envelope>';
                        }


                        Create a function to form a soap request.



                        public function generateSoapRequest($soapBody){
                        return $this->openSoapEnvelope . $this->soapHeader . $soapBody . $this->closeSoapEnvelope;
                        }


                        Define a body & call generateSoapRequest method.
                        e.g:



                        $soapBody           =   '<soap:Body>
                        <tem:GetSomeDetails/>
                        </soap:Body>';

                        $xmlRequest = $this->generateSoapRequest($soapBody);


                        $client = new Client();

                        $options = [
                        'body' => $xmlRequest,
                        'headers' => [
                        "Content-Type" => "text/xml",
                        "accept" => "*/*",
                        "accept-encoding" => "gzip, deflate"
                        ]
                        ];

                        $res = $client->request(
                        'POST',
                        'http://your-soap-endpoint-url',
                        $options
                        );

                        print_r($res->getBody());





                        share|improve this answer




























                          1














                          Guzzle HTTP can be used for SOAP requests & works like a charm:



                          Below is the way I have implemented.



                          Create variables:



                              public function __construct(Request $request) {
                          $this->request = $request;
                          $this->openSoapEnvelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">';
                          $this->soapHeader = '<soap:Header>
                          <tem:Authenticate>
                          <-- any header data goes here-->
                          </tem:Authenticate>
                          </soap:Header>';

                          $this->closeSoapEnvelope = '</soap:Envelope>';
                          }


                          Create a function to form a soap request.



                          public function generateSoapRequest($soapBody){
                          return $this->openSoapEnvelope . $this->soapHeader . $soapBody . $this->closeSoapEnvelope;
                          }


                          Define a body & call generateSoapRequest method.
                          e.g:



                          $soapBody           =   '<soap:Body>
                          <tem:GetSomeDetails/>
                          </soap:Body>';

                          $xmlRequest = $this->generateSoapRequest($soapBody);


                          $client = new Client();

                          $options = [
                          'body' => $xmlRequest,
                          'headers' => [
                          "Content-Type" => "text/xml",
                          "accept" => "*/*",
                          "accept-encoding" => "gzip, deflate"
                          ]
                          ];

                          $res = $client->request(
                          'POST',
                          'http://your-soap-endpoint-url',
                          $options
                          );

                          print_r($res->getBody());





                          share|improve this answer


























                            1












                            1








                            1







                            Guzzle HTTP can be used for SOAP requests & works like a charm:



                            Below is the way I have implemented.



                            Create variables:



                                public function __construct(Request $request) {
                            $this->request = $request;
                            $this->openSoapEnvelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">';
                            $this->soapHeader = '<soap:Header>
                            <tem:Authenticate>
                            <-- any header data goes here-->
                            </tem:Authenticate>
                            </soap:Header>';

                            $this->closeSoapEnvelope = '</soap:Envelope>';
                            }


                            Create a function to form a soap request.



                            public function generateSoapRequest($soapBody){
                            return $this->openSoapEnvelope . $this->soapHeader . $soapBody . $this->closeSoapEnvelope;
                            }


                            Define a body & call generateSoapRequest method.
                            e.g:



                            $soapBody           =   '<soap:Body>
                            <tem:GetSomeDetails/>
                            </soap:Body>';

                            $xmlRequest = $this->generateSoapRequest($soapBody);


                            $client = new Client();

                            $options = [
                            'body' => $xmlRequest,
                            'headers' => [
                            "Content-Type" => "text/xml",
                            "accept" => "*/*",
                            "accept-encoding" => "gzip, deflate"
                            ]
                            ];

                            $res = $client->request(
                            'POST',
                            'http://your-soap-endpoint-url',
                            $options
                            );

                            print_r($res->getBody());





                            share|improve this answer













                            Guzzle HTTP can be used for SOAP requests & works like a charm:



                            Below is the way I have implemented.



                            Create variables:



                                public function __construct(Request $request) {
                            $this->request = $request;
                            $this->openSoapEnvelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">';
                            $this->soapHeader = '<soap:Header>
                            <tem:Authenticate>
                            <-- any header data goes here-->
                            </tem:Authenticate>
                            </soap:Header>';

                            $this->closeSoapEnvelope = '</soap:Envelope>';
                            }


                            Create a function to form a soap request.



                            public function generateSoapRequest($soapBody){
                            return $this->openSoapEnvelope . $this->soapHeader . $soapBody . $this->closeSoapEnvelope;
                            }


                            Define a body & call generateSoapRequest method.
                            e.g:



                            $soapBody           =   '<soap:Body>
                            <tem:GetSomeDetails/>
                            </soap:Body>';

                            $xmlRequest = $this->generateSoapRequest($soapBody);


                            $client = new Client();

                            $options = [
                            'body' => $xmlRequest,
                            'headers' => [
                            "Content-Type" => "text/xml",
                            "accept" => "*/*",
                            "accept-encoding" => "gzip, deflate"
                            ]
                            ];

                            $res = $client->request(
                            'POST',
                            'http://your-soap-endpoint-url',
                            $options
                            );

                            print_r($res->getBody());






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 15 '18 at 13:21









                            user3785966user3785966

                            112




                            112






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19170846%2fusing-guzzle-to-consume-soap%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                List item for chat from Array inside array React Native

                                Thiostrepton

                                Caerphilly