2

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?

j0k
  • 22,600
  • 28
  • 79
  • 90
shinercoder
  • 31
  • 1
  • 1
  • 4

3 Answers3

3

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 ;)

Community
  • 1
  • 1
Gergely Szilagyi
  • 3,813
  • 1
  • 14
  • 12
0

To fix the Content-Type header issues, I switched the soap_version to SOAP_1_1

"soap_version" => SOAP_1_1,

Then I got a more interesting error message, which Christian Burger used to get us a little further to include the ShipCarr parameter.

Building on that, I looked at the XSD and here's an updated $params value that worked:

$params->ShipCarr = 'scUnknown';

This returned:

POST /PSShipCarrierAPI/PSShipCarrier.svc HTTP/1.1
Host: test.psdataservices.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.8
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/IPSShipCarrier/Authenticate"
Content-Length: 856

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://tempuri.org/IPSShipCarrier/Authenticate"><SOAP-ENV:Header><ns2:Authenticate><item><key>UserName</key><value>blahremoved</value></item><item><key>Password</key><value>blahremoved</value></item><item><key>AuthToken</key><value>blahremoved</value></item><item><key>SOAPAction</key><value>http://tempuri.org/IPSShipCarrier/Authenticate</value></item><item><key>Action</key><value>Authenticate</value></item></ns2:Authenticate></SOAP-ENV:Header><SOAP-ENV:Body><ns1:Authenticate><ns1:UserName>blahremoved</ns1:UserName><ns1:Password>blahremoved</ns1:Password><ns1:AuthToken>blahremoved</ns1:AuthToken><ns1:ShipCarr>scUnknown</ns1:ShipCarr></ns1:Authenticate></SOAP-ENV:Body></SOAP-ENV:Envelope>
HTTP/1.1 200 OK
Content-Length: 325
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 25 Jun 2012 20:34:42 GMT
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><AuthenticateResponse xmlns="http://tempuri.org/"><AuthenticateResult i:nil="true" xmlns:a="http://schemas.datacontract.org/2004/07/ShipCarriers.Contract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/></AuthenticateResponse></s:Body></s:Envelope>

However, making subsequent requests gives me a 500 internal server error.

Adam Trachtenberg
  • 2,231
  • 1
  • 14
  • 18
0

Changing the SOAP version definitely gets you a bit further. But then, from looking at the stack trace it seems the Authenticate methods requires parameters that you are not setting. Here is the minimum code you need, without know what the shipCarr object should look like:

$options = array(
    "soap_version" => SOAP_1_1,
    "trace"=>1,
    'exceptions'=>true,
);

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

$params = new StdClass();
$params->UserName = "blahremoved";
$params->Password = "blahremoved";
$params->AuthToken = "blahremoved";
$params->ShipCarr = array();
$params->ClientName = "blahremoved";
$response = $client->Authenticate($params);
var_dump($response);

This is the response:

[a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:ShipCarr. The InnerException message was 'Invalid enum value 'Array' cannot be deserialized into type 'ShipCarriers.Contract.scShipCarrier'. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'.  Please see InnerException for more details.