PHP SOAP Header does not match HTTP SOAP Action, how to set it?

shinercoder picture shinercoder · Jun 11, 2012 · Viewed 11.7k times · Source

I've tried everything! I'm using this WSDL and am simply just trying to authenticate. I keep getting this error:

The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IPSShipCarrier/Authenticate'

Here is my code:

    $options = array(
        "soap_version" => SOAP_1_2,
        "trace"=>1,
        'UserName'=>'blahremoved',
        'Password'=>'blahremoved',
        'AuthToken'=>'blahremoved',
        'SOAPAction'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
        'Action'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
        'uri'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
        'exceptions'=>true );

    $client = new SoapClient( "http://test.psdataservices.com/PSShipCarrierAPI/PSShipCarrier.svc?WSDL", $options );

    $auth = array(
        'UserName'=>'blahremoved',
        'Password'=>'blahremoved',
        'AuthToken'=>'blahremoved',
        'SOAPAction'=>'http://tempuri.org/IPSShipCarrier/Authenticate',
        'Action'=>"Authenticate"
    );
    $header = new SoapHeader('http://tempuri.org/IPSShipCarrier/Authenticate','Authenticate',$auth,false);

    $client->__setSoapHeaders($header);

    $params = new StdClass;
    $params->Action = "http://tempuri.org/IPSShipCarrier/Authenticate";
    $params->SOAPAction = "http://tempuri.org/IPSShipCarrier/Authenticate";
    $params->UserName = "blahremoved";
    $params->Password = "blahremoved";
    $params->AuthToken = "blahremoved";
$client->Authenticate($params);

Let me know what you think?

Answer

Gergely Szilagyi picture Gergely Szilagyi · Jun 27, 2012

When trying to access a -yet- unknown webservice, you should start with soapUi. http://www.soapui.org/ That would've shown you in 2 mins, that

it's a SOAP 1.1 service

this is the minimal content for the Authenticate port:

<tem:Authenticate>
     <!--Optional:-->
     <!--type: string-->
     <tem:ClientName>aat</tem:ClientName>
     <!--Optional:-->
     <!--type: string-->
     <tem:UserName>soa</tem:UserName>
     <!--Optional:-->
     <!--type: string-->
     <tem:Password>quaaao</tem:Password>
     <!--Optional:-->
     <!--type: string-->
     <tem:AuthToken>verraauras</tem:AuthToken>
     <!--Optional:-->
     <!--type: scShipCarrier - enumeration: [scUnknown,scStampsCom,scUPS,scEndicia,scFedEx]-->
     <tem:ShipCarr>scUnknown</tem:ShipCarr>
  </tem:Authenticate>

their messagerouter must be based on soap-action alone, so using Action is pointless and unnecessary

so yes, using soapUi would've saved your day ;)