title: Sending form data to a SOAP API, can't get the format of the --soapCall right
body: <p>I am working from a php form to send data to a CRM to collect data and put it in the correct spot on the CRM to notify the correct division in the company. Someone else wrote the API to collect the information and they supplied me with the SOAP URL. They supplied me with sample XML that has been shown to work in SOAPUI to give the correct GUID response back.</p>
  
  <p>I have coded the PHP to collect the data from the form, put it in the same xml code that was used to test the API in SOAP API. I am having a hard time getting the proper submit code. My issue is similar to the page here: <a href="https://stackoverflow.com/questions/23425512/how-do-i-send-xml-data-to-an-api-via-soap-in-php">How do I send XML data to an API via SOAP in PHP?</a>. However using the $client->Submit gives me an error saying this is not a function.
  So I went back to the SOAP 1.2 specs and have tried __soapCall(function(array)).
  I get nothing back in response. I have tried a couple of other things but this seems like it should work.</p>
  
  <p>Example of xml to send:</p>
  
  <pre><code>    &lt;soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
              &lt;soapenv:header&gt;
              &lt;soapenv:body&gt;
                  &lt;tem:addnewlead&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:firstname&gt;test&lt;/tem:firstname&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:lastname&gt;test2&lt;/tem:lastname&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:emailaddress&gt;test@test.com&lt;/tem:emailaddress&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:mainphone&gt;555-555-5555&lt;/tem:mainphone&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:companyname&gt;testtest&lt;/tem:companyname&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:interest&gt;testtesttest&lt;/tem:interest&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:requesttype&gt;test&lt;/tem:requesttype&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:requestdetails&gt;testtesttest&lt;/tem:requestdetails&gt;
                  &lt;/tem:addnewlead&gt;
              &lt;/soapenv:body&gt;
          &lt;/soapenv:header&gt;
   &lt;/soapenv:envelope&gt;
  </code></pre>
  
  <p>This is the php with the code to form the xml removed for brevity as I know this works, using the xml above to send which matches the previous coder's testing in SOAPUI:</p>
  
  <pre><code>    &lt;?php 
           $URL = 'http://zzzzzzzz.com/APIService.svc';
           $send = "&lt;soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'&gt;
              &lt;soapenv:Header/&gt;
              &lt;soapenv:Body&gt;
                  &lt;tem:ADDNEWLEAD&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:FirstName&gt;test&lt;/tem:FirstName&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:LastName&gt;test2&lt;/tem:LastName&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:emailAddress&gt;test@test.com&lt;/tem:emailAddress&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:MainPhone&gt;555-555-5555&lt;/tem:MainPhone&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:CompanyName&gt;testtest&lt;/tem:CompanyName&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:Interest&gt;testtesttest&lt;/tem:Interest&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:RequestType&gt;test&lt;/tem:RequestType&gt;
                      &lt;!--Optional--&gt;
                      &lt;tem:RequestDetails&gt;testtesttest&lt;/tem:RequestDetails&gt;
                  &lt;/tem:ADDNEWLEAD&gt;
              &lt;/soapenv:Body&gt;
          &lt;/soapenv:Envelope&gt;";
        print_r($send);
       try {
           $client = new SoapClient("http://zzzzzzzz.com/APIService.svc?WSDL",array(
          'location'      =&gt; $URL,
          'uri'           =&gt; "http://zzzzzzz.com/",
          'trace'         =&gt; 1,
          'exceptions'    =&gt; true
      ));
      $return = $client-&gt;__soapCall(array('ADDNEWLEAD' =&gt; $send));
      $functions = $client-&gt;__getFunctions();
      // Some other code that I thought I would try as I am not the best SOAP API writer as you can tell by now.
      //  $return = $client-&gt;__soapCall(array(DoWork $xml, ADDNEWLEAD $send));
      //  $return = $client-&gt;DoWork(ADDNEWLEAD($send));
     //   $return = $client-&gt;__soapCall('DoWork',array('DoWork' =&gt; null,'ADDNEWLEAD' =&gt; $send));
      echo '&lt;pre&gt;'; //show response on screen
       echo '&lt;br&gt;-';
     print_r($functions);
       echo '&lt;br&gt;+';
     print_r($return);
     echo '&lt;/pre&gt;';
     } catch(SoapFault $e) {
      echo '&lt;h3&gt;Exception&lt;/h3&gt;';
      echo '&lt;pre&gt;';
     print_r($e);
     echo '&lt;/pre&gt;';
    }
    die(); ?&gt;
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>   Array
     (
       [0] =&gt; DoWorkResponse DoWork(DoWork $parameters)
       [1] =&gt; ADDNEWLEADResponse ADDNEWLEAD(ADDNEWLEAD $parameters)
     )
     stdClass Object (
          [ADDNEWLEADResult] =&gt;  )
  </code></pre>
  
  <p>Where it is black, I should be getting a confirmation code from the API.</p>
  
  <p>Any help appreciated.
  Thank you.</p>
  
  <p>I have also received this xml response as well when the submission did not work:</p>
  
  <blockquote>
    <p>
  </blockquote>
  
  <pre><code>            /**
  
              * Class GF_Services_API
  
              *
  
              * Accesses the API for Service Request data
  
              *
  
              * @since 1.0.0
  
              */
  
  
  
              // Exit if accessed directly
  
              if ( ! defined( 'ABSPATH' ) ) exit;
  
  
  
              ini_set('default_socket_timeout', 120);
  
  
  
              class GF_Services_API {
  
  
  
                     /**
  
                     * @var               GF_Services_API $endpoint The Endpoint that we ping for data
  
                     * @since             1.0.0
  
                     */
  
                     private $endpoint = 'http://xxxxxxxxxxxxxxxx/Alpha.svc?wsdl';
  
  
  
                     /**
  
                     * GF_Services_API constructor.
  
                     *
  
                     * @since 1.0.0
  
                     */
  
                     function __construct() {
  
                     }
  
  
  
                     /**
  
                     * I guess this is marginally easier than using Capture Groups in Regex...?
  
                     * Maybe it is more efficient, don't feel like running a benchmark. This is how it was to begin with.
  
                     * 
  
                      * @param             string $haystack Input to Search
  
                     * @param             string $start    Opening Tag
  
                     * @param             string $end      Closing Tag
  
                     *              
  
                      * @access            private
  
                     * @since             1.0.0
  
                     * @return            string String between the opening and closing Tag
  
                     */
  
                     private function substring_between( $haystack, $start, $end ) {
  
  
  
                             if ( strpos( $haystack, $start ) === false ||
  
                                    strpos( $haystack, $end ) === false) {
  
                                    return false;
  
                             }
  
                             else {
  
  
  
                                    $start_position = strpos( $haystack, $start ) + strlen( $start );
  
                                    $end_position = strpos( $haystack, $end );
  
  
  
                                    return substr( $haystack, $start_position, $end_position - $start_position );
  
  
  
                             }
  
  
  
                     }
  
  
  
  
  
                     /**
  
                     * Grab Information from the API using a Ticket Number
  
                     * 
  
                      * @param             string $ticket_number Ticket Number
  
                     *                                      
  
                      * @access            public
  
                     * @since             1.0.0
  
                     * @return            array  API Data for the Ticket Number
  
                     */
  
                     public function get_information_by_ticket_number( $ticket_number = '' ) {
  
  
  
                             $return_array = array();
  
  
  
                             if ( $ticket_number != '' ) {
  
  
  
                                    try {
  
  
  
                                            $wsdl = $this-&gt;endpoint;
  
  
  
                                            // options for OpenSSL in php 5.6.5
  
                                            $opts = array(
  
                                                   'ssl' =&gt; array(
  
                                                          'ciphers' =&gt; 'RC4-SHA',
  
                                                          'verify_peer' =&gt; false,
  
                                                          'verify_peer_name' =&gt; false
  
                                                   )
  
                                            );
  
  
  
                                            // SOAP 1.2 client
  
                                            $params = array(
  
                                                   'encoding' =&gt; 'UTF-8',
  
                                                   'verifypeer' =&gt; false,
  
                                                   'verifyhost' =&gt; false,
  
                                                   //'soap_version' =&gt; SOAP_1_2, SOAP v1.2 doesn't support text/html which we need
  
                                                   'trace' =&gt; 1,
  
                                                   'exceptions' =&gt; 1,
  
                                                   'connection_timeout' =&gt; 180,
  
                                                   'stream_context' =&gt; stream_context_create( $opts )
  
                                            );
  
  
  
                                            $cliente = new SoapClient( $wsdl, $params );
  
  
  
                                            $data = array(
  
                                                   "TicketNo" =&gt; $ticket_number,
  
                                                   "Key1" =&gt; '76xxxxxxxxxxxxxx94',
  
                                                   "Key2" =&gt; '6x-xxxxxxxxxxxxxxx4xxxxxxxxxxxxx16'
  
                                            );
  
  
  
                                            $result = $cliente-&gt;__call( 'CheckServiceTicket', array( $data ) );
  
                                            $result_data = $result-&gt;CheckServiceTicketResult-&gt;any;
  
  
  
                                           $return_array['serial_number'] = $this-&gt;substring_between( $result_data, '&lt;serial_no&gt;', '&lt;/serial_no&gt;' );
  
                                           $return_array['descr'] = $this-&gt;substring_between( $result_data, '&lt;descr&gt;', '&lt;/descr&gt;' );
  
                                           $return_array['contract_id'] = $this-&gt;substring_between( $result_data, '&lt;Contract_ID&gt;', '&lt;/Contract_ID&gt;' );
  
                                           $return_array['contract_status'] = $this-&gt;substring_between( $result_data, '&lt;Contract_Status&gt;', '&lt;/Contract_Status&gt;' );
  
                                           $return_array['contract_expiry_date'] = $this-&gt;substring_between( $result_data, '&lt;Contract_Expiry_date&gt;', '&lt;/Contract_Expiry_date&gt;' );
  
                                           $return_array['address_1'] = $this-&gt;substring_between( $result_data, '&lt;address_1&gt;','&lt;/address_1&gt;');
  
                                           $return_array['address_2'] = $this-&gt;substring_between( $result_data, '&lt;address_2&gt;', '&lt;/address_2&gt;' );
  
                                           $return_array['address_3'] = $this-&gt;substring_between( $result_data, '&lt;address_3&gt;', '&lt;/address_3&gt;' );
  
                                           $return_array['city'] = $this-&gt;substring_between( $result_data, '&lt;city&gt;', '&lt;/city&gt;' );
  
                                           $return_array['state'] = $this-&gt;substring_between( $result_data, '&lt;state&gt;', '&lt;/state&gt;' );
  
                                           $return_array['zip'] = $this-&gt;substring_between( $result_data, '&lt;zip&gt;', '&lt;/zip&gt;' );
  
                                           $return_array['country'] = $this-&gt;substring_between( $result_data, '&lt;country&gt;', '&lt;/country&gt;' );
  
                                           $return_array['company_name'] = $this-&gt;substring_between( $result_data, '&lt;Company_Name&gt;', '&lt;/Company_Name&gt;' );
  
                                           $return_array['device_type'] = $this-&gt;substring_between( $result_data, '&lt;Device_Type&gt;', '&lt;/Device_Type&gt;' );
  
                                           $return_array['state'] = $this-&gt;get_us_state_name( $return_array['state'] );
  
                                           $return_array['contract_expiry_date'] = date( "F d, Y", strtotime( $return_array['contract_expiry_date'] ) );
  
  
  
                                    }
  
                                    catch ( Exception $e ) {
  
                                            echo "Error: " . $e-&gt;getMessage();
  
                                    }
  
  
  
                             }
  
  
  
                             return $return_array;
  
  
  
                     }
  
  
  
                     /**
  
                     * Gets an Array of Service Requests Information (Including Status) via an Email Address
  
                     * 
  
                      * @param             string $email Email Address
  
                     *                             
  
                      * @access            public
  
                     * @since             1.0.0
  
                     * @return            array  Array of Service Request Info
  
                     */
  
                     public function get_information_by_email_address( $email = '' ) {
  
  
  
                             $return_array = array();
  
  
  
                             if ( $email != '' ) {
  
  
  
                                    try {
  
  
  
                                            $wsdl = $this-&gt;endpoint;
  
  
  
                                            // options for OpenSSL in php 5.6.5
  
                                            $opts = array(
  
                                                   'ssl' =&gt; array(
  
                                                          'ciphers' =&gt; 'RC4-SHA',
  
                                                          'verify_peer' =&gt; false,
  
                                                          'verify_peer_name' =&gt; false
  
                                                   )
  
                                            );
  
  
  
                                            // SOAP 1.2 client
  
                                            $params = array(
  
                                                   'encoding' =&gt; 'UTF-8',
  
                                                   'verifypeer' =&gt; false,
  
                                                   'verifyhost' =&gt; false,
  
                                                   //'soap_version' =&gt; SOAP_1_2, SOAP v1.2 doesn't support text/html which we need
  
                                                   'trace' =&gt; 1,
  
                                                   'exceptions' =&gt; 1,
  
                                                   'connection_timeout' =&gt; 180,
  
                                                   'stream_context' =&gt; stream_context_create( $opts )
  
                                            );
  
  
  
                                            $client = new SoapClient( $wsdl, $params );
  
  
  
                                            $data = array(
  
                                                   "Email" =&gt; $email,
  
                                                   "Key1" =&gt; '7x',
  </code></pre>
  
  <p>xxxxxxxxxxxxxxxxxxxxxxxxxxx
                                                       "Key2" => '6xxxxxxxxxxxxxxxxxxxxxx'</p>
  
  <pre><code>                                          );
  
  
  
                                            $result = $client-&gt;__call( 'QueryTicketInfo', array( $data ) );
  
  
  
                                            $xml = $result-&gt;QueryTicketInfoResult-&gt;any;
  
  
  
                                            // Remove namespaces
  
                                            $xml = str_replace( array( "diffgr:", "msdata:" ), '', $xml );
  
                                            $xml = "&lt;package&gt;" . $xml . "&lt;/package&gt;";
  
                                            $data = simplexml_load_string( $xml );
  
                                            $tickets = $data-&gt;diffgram-&gt;DocumentElement-&gt;WS0002;
  
  
  
                                            foreach ( $tickets as $ticket ) {
  
  
  
                                                   $_result = array();
  
                                                   $_result['Opened'] = (string) $ticket-&gt;Opened;
  
                                                   $_result['LastAction'] = (string) $ticket-&gt;LastAction;
  
                                                   $_result['Enteredby'] = (string) $ticket-&gt;Enteredby;
  
                                                   $_result['TicketNumber'] = (string) $ticket-&gt;TicketNumber;
  
                                                   $_result['ProblemDescription'] = (string) $ticket-&gt;ProblemDescription;
  
                                                   $_result['CurrentStatus'] = (string) $ticket-&gt;CurrentStatus;
  
                                                   $_result['CustomerName'] = (string) $ticket-&gt;CustomerName;
  
                                                   $_result['CalledInBy'] = (string) $ticket-&gt;CalledInBy;
  
                                                   $_result['Email'] = (string) $ticket-&gt;Email;
  
                                                   $_result['ServiceAgent'] = (string) $ticket-&gt;ServiceAgent;
  
                                                   $_result['PartNumber'] = (string) $ticket-&gt;PartNumber;
  
                                                   $_result['PartDescription'] = (string) $ticket-&gt;PartDescription;
  
                                                   $_result['SerialNumber'] = (string) $ticket-&gt;SerialNumber;
  
                                                   $_result['City'] = (string) $ticket-&gt;City;
  
                                                   $_result['State'] = (string) $ticket-&gt;State;
  
                                                   $_result['LastActivity'] = (string) $ticket-&gt;LastActivity;
  
                                                   $_result['DO'] = (string) $ticket-&gt;DO;
  
  
  
                                                   $return_array[] = $_result;
  
  
  
                                            }
  
  
  
                                    }
  
                                    catch ( Exception $e ) {
  
                                            echo "Error: " . $e-&gt;getMessage();
  
                                    }
  
  
  
                             }
  
  
  
                             return $return_array;
  
  
  
                     }
  
  
  
              }
  </code></pre>