PHP and no Soap action header

12,755

I had a similar issue, but I was using cURL and not the SoapClient, though the solution may be the same.

When sending a request to the end service, you have to send a header specifying the Content-Type. In this header, you can also specify the action, or "soap action".

$headers = array();
$headers[] = 'Content-Type: application/soap+xml; charset=utf-8; action="[soap action goes here]"';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

In my case, and what appears to be the same as yours, the wsdl lists the following:

<wsdl:operation name="getProducts">
    <soap:operation soapAction=""/>
    <!-- trimmed -->
</wsdl:operation>

At first, I see soapAction="", so I set action="" in the headers being sent. This failed. The correct data that goes into the header is the operation, making it action="getProducts".

Based on the manual for SoapClient and the answer to php using SOAP with a different SoapAction, your request should have worked with:

$client = new SoapClient( "http://myWebsite.com/services/MyFirstWebService?wsdl", $options );
$result = $client->__soapCall( "getItemField", array('123456') );

Did you ever omit the $options sent to __soapCall() to simply not specify an action (rather than passing in a blank one)?

Share:
12,755
kingrichard2005
Author by

kingrichard2005

Test Engineer at ViaSat

Updated on June 19, 2022

Comments

  • kingrichard2005
    kingrichard2005 almost 2 years

    I'm trying to call a remote web service, within my company. For proprietary reasons I cannot provide the URL to the web service. The web service has a single function called getItemField. It is a small test service that I'm trying to run PHP against, the service description is as follows:

    <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://www.oracle.com/ws/MyFirstWebService" xmlns:intf="http://www.oracle.com/ws/MyFirstWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://www.w3.org/1999/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.oracle.com/ws/MyFirstWebService">
    <!--
    WSDL created by Apache Axis version: 1.2alpha Built on Oct 23, 2007 (12:09:54 IST)
    -->
    <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.oracle.com/ws/MyFirstWebService">
    <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
    <complexType name="ArrayOf_xsd_string">
    <complexContent>
    <restriction base="soapenc:Array">
    <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
    </restriction>
    </complexContent>
    </complexType>
    </schema>
    </wsdl:types>
    <message name="getItemFieldRequest">
    <part name="args" type="impl:ArrayOf_xsd_string"/>
    </message>
    <message name="getItemFieldResponse">
    <part name="getItemFieldReturn" type="soapenc:string"/>
    </message>
    <portType name="MyFirstWebService">
    <operation name="getItemField" parameterOrder="args">
    <input message="impl:getItemFieldRequest" name="getItemFieldRequest"/>
    <output message="impl:getItemFieldResponse" name="getItemFieldResponse"/>
    </operation>
    </portType>
    <binding name="MyFirstWebServiceSoapBinding" type="impl:MyFirstWebService">
    <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getItemField">
    <wsdlsoap:operation soapAction=""/>
    <input name="getItemFieldRequest">
    <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://first" use="encoded"/>
    </input>
    <output name="getItemFieldResponse">
    <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.oracle.com/ws/MyFirstWebService" use="encoded"/>
    </output>
    </operation>
    </binding>
    <service name="MyFirstWebServiceService">
    <port binding="impl:MyFirstWebServiceSoapBinding" name="MyFirstWebService">
    <wsdlsoap:address location="http://myWebsite.com/services/MyFirstWebService"/>
    </port>
    </service>
    </definitions>
    

    I can connect to the service just fine and print out the name of the single function and type, but when I try to call a function I get 'no SOAPAction header!' error. My PHP code to call the service function is as follows:

    $options = array(
                    // Dev
                    'soap_version'=>SOAP_1_2, 
                    'exceptions'=>true, 
                    'trace'=>1, 
                    'cache_wsdl'=>WSDL_CACHE_NONE,
                    'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
    
                    // Credentials
                    'login' => 'user', 
                    'password' => 'pass'
                );        
    
    // Connected successfully
                $client = new SoapClient( "http://myWebsite.com/services/MyFirstWebService?wsdl", $options );
    
        //Params
            $params = array( '123456' );
    
            //Options
            $options = array( 'soapaction' => '""' );
    
            //Call function (Both methods below throw the same 'no SOAPAction header!' error)
            //$result = $client->getItemField( new SoapParam($params, "getItemFieldRequest") );
            $result = $client->__soapCall( "getItemField", array('123456'), $options );
    

    Based on the description of the service it doesn't appear to have a soapaction defined. The line I see with soapAction is <wsdlsoap:operation soapAction=""/>. I tried to specify a blank soapAction since there's none defined, but that didn't seem to work. Is the web service definition itself incomplete? Or am I missing some parameter in my client-side application call? Thanks in advance.

    UPDATE:

    Tried to specify the method name as the soap action, but htat didn't work.

        //Params
        $params = array( '123456' );
    
        //Options
        $options = array( 'soapaction' => 'getItemField' );
    
        //Call function (STILL THROWS 'no SOAPAction header!')
        $result = $client->__soapCall( "getItemField", $params, $options );
    

    What am I supposed to do if no soapAction is specified in the wsdl, i.e. if it's set to "".