ws-security and nusoap not working - php

for a project I need to contact another companies webservice. They have made it on Soap, and it's all detailed etc. I found out the variables and types and what method etc.
They also stated that I should use WS-security with pwd and username in the headers.
So I made this with nusoap:
require_once('../lib/nusoap.php');
$client = new nusoap_client("http://webservice.client.com/cir.asmx?WSDL", 'wsdl');
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$client->soap_defencoding = 'UTF-8';
$result = $client->call('GetLastUpdate');
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
then I added:
$client->setCredentials('******','*******','basic');
which didn't work, so I looked up the ws-security style and added the following instead:
$auth='<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>********</wsse:Username>
<wsse:Password Type="wsse:PasswordText">*******</wsse:Password>
<wsse:Nonce>'.base64_encode(pack('H*',$nonce)).'</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'.time().'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
$client->setHeaders($auth);
Which didn't work either...they give the same error....this is what it returns:
Fault
Array
(
[faultcode] => q0:Security
[faultstring] => Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.
[faultactor] => http://webservice.client.com/cir.asmx
)
Request
POST /cir.asmx HTTP/1.0
Host: webservice.client.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.client.com/namespaces/cir01/GetLastUpdate"
Content-Length: 967
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2278="http://tempuri.org"><SOAP-ENV:Header><wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>*******</wsse:Username>
<wsse:Password Type="wsse:PasswordText">********</wsse:Password>
<wsse:Nonce></wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">1300862463</wsu:Created>
</wsse:UsernameToken>
</wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body><GetLastUpdate xmlns="http://www.client.com/namespaces/cir01"></GetLastUpdate></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 500 Internal Server Error
Connection: close
Date: Wed, 23 Mar 2011 06:39:57 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 1421
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><soap:Header><wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action><wsa:MessageID>urn:uuid:b8c93511-b6e6-4247-9ab5-65bd4a6aa286</wsa:MessageID><wsa:RelatesTo>urn:uuid:6dfa917b-3163-4ae9-bd84-0855b7a1329e</wsa:RelatesTo><wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-4d37a6a5-9445-40d6-8660-a724999cc3bc"><wsu:Created>2011-03-23T06:39:57Z</wsu:Created><wsu:Expires>2011-03-23T06:44:57Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><soap:Fault><faultcode xmlns:q0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">q0:Security</faultcode><faultstring>Header http://schemas.xmlsoap.org/ws/2004/08/addressing:Action for ultimate recipient is required but not present in the message.</faultstring><faultactor>http://webservice.client.com/cir.asmx</faultactor></soap:Fault></soap:Body></soap:Envelope>

Please try setting the header using following method:
$client = new SoapClient("Wsdl_URL", array("trace" => 0));
$WSHeader = array(
"UsernameToken"=>array(
"Username"=>"YourUserName",
"Password"=>"YourPassword",
)
);
$header[] = new
SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security",$WSHeader);
$client->__setSoapHeaders($header);
$REsponse = $client->YourRequest();

Related

How to create a PHP SOAP Request and Response

I am working with an API and I am new to PHP SOAP.. I am trying to create a request to get a vehicle value and am looking to get the response value.
The following is a sample SOAP 1.1 request. The placeholders shown need to be replaced with actual values.
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?xml version="1.0" encoding="utf-8"?>
<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>
<getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
<vehicleRequest>
<Vin>string</Vin>
<Region>int</Region>
<Mileage>int</Mileage>
</vehicleRequest>
</getDefaultVehicleAndValueByVin>
Here is the SOAP Client URL Call -
$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(
// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
This is what ive tried but get no result -
$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
$params = new \SoapVar("<vehicleRequest><Vin>5YFBURHE3FP331896</Vin><Region>10</Region><Mileage>100000</Mileage></vehicleRequest>", XSD_ANYXML);
$result = $client->Echo($params);
Another method I tried but get error parsing WSDL
$wsdl = '
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?xml version="1.0" encoding="utf-8"?>
<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>
<getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
<vehicleRequest>
<Vin>5YFBURHE3FP331896</Vin>
<Region>1</Region>
<Mileage>100</Mileage>
</vehicleRequest>
</getDefaultVehicleAndValueByVin>
</soap:Body>
</soap:Envelope>
';
try {
$clientC = #new SOAPClient($wsdl); for $wsdl
$response = $clientC->getDefaultVehicleAndValueByVin(array('key' => 'val'));
} catch (Exception $e) {
echo $e->getMessage();
}
die(var_dump($response));
Here is the error I get -
SOAP-ERROR: Parsing WSDL: Couldn't load from ' POST /vehicles/vehicle.asmx HTTP/1.1 Host: webservice.nada.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://webservice.nada.com/vehicles/vehicle.asmx?wsdl" 5YFBURHE3FP331896 1 100 ' : failed to load external entity " POST /vehicles/vehicle.asmx HTTP/1.1 Host: webservice.nada.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://webservice.nada.com/vehicles/vehicle.asmx?wsdl"
Something like this should help you get started. I am not 100% familiar with the NADA API so I don't know what valid values are for some of the parameters... you'll have to fill in the correct values (e.g. for Token, Period, VehicleType, and Region).
$clientV = new SoapClient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array('trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
$params = new stdClass();
$params->Token = '';
$params->Period = 1;
$params->VehicleType = '';
$params->Vin = '5YFBURHE3FP331896';
$params->Region = 1;
$params->Mileage = 100;
$result = $clientV->getDefaultVehicleAndValueByVin(array('vehicleRequest' => $params));

Send SOAP Requests using PHP and get the returned response

I am trying integrate a payment gateway in a simple PHP site (my own site) and the gateway accepts data only in SOAP format. I have absolutely no idea what the SOAP is, but thanks to Google I now know how it looks like (at least).
Basically, I need to send a bunch of customer data and payment data to the gateway to act according to the response receive. Here are the sample request code and sample response code. They only provided the URLto post to and that is http://69.94.141.22/SaveTransactions.asmx.
Request
POST /SaveTransactions.asmx HTTP/1.1
Host: 69.94.141.22
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendTransactionsAction xmlns="http://tempuri.org/">
<strUserName>string</strUserName>
<strPassword>string</strPassword>
<strSecureKey>string</strSecureKey>
<strFirstName>string</strFirstName>
<strLastName>string</strLastName>
<strPhoneNumber>string</strPhoneNumber>
<strStreetNumber>string</strStreetNumber>
<strUnitNumber>string</strUnitNumber>
<strStreetName>string</strStreetName>
<strCity>string</strCity>
<strState>string</strState>
<strZipCode>string</strZipCode>
<strEmailAddress>string</strEmailAddress>
<strBankName>string</strBankName>
<strRoutingNo>string</strRoutingNo>
<strAccountNumber>string</strAccountNumber>
<strCheckNo>string</strCheckNo>
<strAmount>string</strAmount>
<strNotes>string</strNotes>
</SendTransactionsAction>
</soap12:Body>
</soap12:Envelope>
Response
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendTransactionsActionResponse xmlns="http://tempuri.org/">
<SendTransactionsActionResult>string</SendTransactionsActionResult>
</SendTransactionsActionResponse>
</soap12:Body>
</soap12:Envelope>
How do I post these to the URL provided using PHP and how do I get that response SendTransactionsActionResult from the returned response?
I am not asking you to do it for me, but a simple get started like codes will help a lot.
Thanks in advance
You can archive this by using Curl, php soapClient or NuSOAP
Below i have shown you how to use NuSOAP library
Also the WSDL is location in http://69.94.141.22/SaveTransactions.asmx?WSDL
$client = new nusoap_client("http://69.94.141.22/SaveTransactions.asmx?WSDL", true); // this should be the wsdl location
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
// Use basic authentication method
$client->setCredentials("username", "password", "basic"); //set here the credentials if need for the wsdl
$client->setHeaders('<SendTransactionsAction xmlns="http://tempuri.org/">
<strUserName>string</strUserName>
<strPassword>string</strPassword>
<strSecureKey>string</strSecureKey>
<strFirstName>string</strFirstName>
<strLastName>string</strLastName>
<strPhoneNumber>string</strPhoneNumber>
<strStreetNumber>string</strStreetNumber>
<strUnitNumber>string</strUnitNumber>
<strStreetName>string</strStreetName>
<strCity>string</strCity>
<strState>string</strState>
<strZipCode>string</strZipCode>
<strEmailAddress>string</strEmailAddress>
<strBankName>string</strBankName>
<strRoutingNo>string</strRoutingNo>
<strAccountNumber>string</strAccountNumber>
<strCheckNo>string</strCheckNo>
<strAmount>string</strAmount>
<strNotes>string</strNotes>
</SendTransactionsAction>
');
$result = "";
if ($client) {
$result = $client->call("SendTransactionsAction"); // soap action
}
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>zip code</h2><pre>";
print_r($result);
echo "</pre>";
}
}
echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
Using the WSDL from http://69.94.141.22/SaveTransactions.asmx?WSDL, you could generate the corresponding package from wsdltophp.com in order to be sure on how to structure your request in PHP as every element will be a PHP object with setters/getters. It uses the native PHP SoapClient class so you'll understand easily and quickly who to send these requests if you're familiar with PHP

PHP soap response return with NaN

i'm sorry if the title might misleading, i'm kinda dumb but could you give me a little hint for me.
i'm trying for bmi web service
soap request
POST /webservices/bmiservice.asmx HTTP/1.1
Host: www.beetledev.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.beetledev.com/getBmiValue"
<?xml version="1.0" encoding="utf-8"?>
<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>
<getBmiValue xmlns="http://www.beetledev.com">
<w>double</w>
<h>double</h>
</getBmiValue>
</soap:Body>
</soap:Envelope>
soap response
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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>
<getBmiValueResponse xmlns="http://www.beetledev.com">
<getBmiValueResult>double</getBmiValueResult>
</getBmiValueResponse>
</soap:Body>
</soap:Envelope>
PHP coding
<?php
require_once "lib/nusoap.php";
$client = new nusoap_client("http://www.beetledev.com/webservices/bmiservice.asmx");
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $client->call('getBmiValue',array('w' => 62, 'h' =>167),null, 'http://www.beetledev.com/getBmiValue');
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>BMI</h2><pre>";
echo $result;
echo "</pre>";
}
}
echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
?>
result
BMI
NaN
Request
POST /webservices/bmiservice.asmx HTTP/1.0
Host: www.beetledev.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://www.beetledev.com/getBmiValue"
Content-Length: 476
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><getBmiValue><w xsi:type="xsd:int">62</w><h xsi:type="xsd:int">167</h></getBmiValue></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Sun, 27 Apr 2014 14:26:40 GMT
Connection: close
Content-Length: 364
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getBmiValueResponse xmlns="http://www.beetledev.com"><getBmiValueResult>NaN</getBmiValueResult></getBmiValueResponse></soap:Body></soap:Envelope>
i dont know where i do wrong, i'm hoping for a little hint
Thank you
i found the solution to my problem
first
$client = new nusoap_client("http://www.beetledev.com/webservices/bmiservice.asmx");
change to
$client = new nusoap_client('http://www.beetledev.com/webservices/bmiservice.asmx?WSDL',TRUE);
second
$result = $client->call('getBmiValue',array('w' => 62, 'h' =>167),null, 'http://www.beetledev.com/getBmiValue');
change to
$result = $client->call('getBmiValue',array('w' => 62,'h' => 167));
third
the thing is because there are two variable? (not sure with term), so it was kept in an array
please dont mind the variable name
$fConversionRate = (float) $result['getBmiValueResult'];
and done and i get my bmi result.

send xml using nusoap

my soap requestformat should look like this
<?xml version="1.0" encoding="UTF-8"?>
<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>< WsAbcMobileAcctInq xmlns="http://tempuri.org/"><xml_var><HCMSG xmlns="">
<ABC><ABCTRANSID>MOBL</ABCTRANSID></ABC><REF><TXNTYPE>INQ</TXNTYPE><SC_CD>000ACD</SC_CD>
< REFNO>MOBL0000000060018987941MAT</REFNO></REF><FIXPART><TXNDATE>20110105</TXNDATE>
<TXNTIME>11464178</TXNTIME><AGN_CD>000000006001</ AGN_CD ></FIXPART><VARPART>
<AC_NO TYP="N">0000000000008946565</AC_NO>
<IC_NO TYP="N">0008956466546</ IC_NO>
<ID_CD TYP="S">IN</ ID_CD>
</VARPART></HCMSG></xml_var></ WsAbcMobileAcctInq></soap:Body></soap:Envelope>
but the problem is i don't know how to put it using nusoap. here's what i've been doing:
require_once('lib/nusoap.php');
$client = new nusoap_client('http://domain.my/MobileData/Service.asmx', false);
$params = '<?xml version="1.0" encoding="UTF-8"?>
<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>< WsAbcMobileAcctInq xmlns="http://tempuri.org/"><xml_var><HCMSG xmlns="">
<ABC><ABCTRANSID>MOBL</ABCTRANSID></ABC><REF><TXNTYPE>INQ</TXNTYPE><SC_CD>000ACD</SC_CD>
< REFNO>MOBL0000000060018987941MAT</REFNO></REF><FIXPART><TXNDATE>20110105</TXNDATE>
<TXNTIME>11464178</TXNTIME><AGN_CD>000000006001</ AGN_CD ></FIXPART><VARPART>
<AC_NO TYP="N">0000000000008946565</AC_NO>
<IC_NO TYP="N">0008956466546</ IC_NO>
<ID_CD TYP="S">IN</ ID_CD>
</VARPART></HCMSG></xml_var></ WsAbcMobileAcctInq></soap:Body></soap:Envelope>';
$answer = $client->call('WsAbcMobileAcctInq', array('WsAbcMobile' => $params), '', 'http://tempuri.org/WsAbcMobileAcctInq');
$error = $client->getError();
if ($error){
print_r($client->response);
print_r($client->getDebug());
print_r($client->getError());
die();
}
and basically i got this error:
HTTP/1.1 500 Internal Server Error Connection: close Date: Thu, 24 Nov 2011 05:47:47 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/xml; charset=utf-8 Content-Length: 441 soap:ServerServer was unable to process request. ---> Object reference not set to an instance of an object
any clue?

using nusoap returns fault code

making a call to a web service method with nusoap returns an error
array(3) { ["faultcode"]=> string(11) "soap:Client" ["faultstring"]=> string(516) "System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: . at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)" ["detail"]=> string(0) "" }
is the fault in my calling or with the soap server?
$response = $qes->call('GetXhtml',$url);
var_dump($response);
Above is the call to the function, which accepts 1 parameter ($url) which I have checked as valid.
-------FULL CODE-----
<?php
//include nusoap class
require 'extensions/nusoap/lib/nusoap.php';
//connect to QES
$qes = new nusoap_client("https://www.qes24.com/swindon/ppa/uat/contentserver/contentserver/contentserver.asmx");
$qes->useHTTPPersistentConnection();
$qes->soap_defencoding = 'utf-8';
//check connection
$error = $qes->getError();
//get current page
$curl = curPageURL();//function derives current URL
$furl = $curl."?Type=8AFCCCB9-93DC-421E-A617-92A990EC99A7";
$param = array('url' => $furl);
$response = $qes->call('getXhtml', $param, '','http://tempuri.org/GetXhtml', array('content-type' => 'UTF-8'), true,null,'rpc','literal');
fb::log($response);
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($qes->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($qes->response, ENT_QUOTES) . '</pre>';
//*/
The request SHOULD look like this (according to the company providing the service)
POST /swindon/ppa/uat/ContentServer/ContentServer/ContentServer.asmx HTTP/1.1
Host: www.qes24.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetXhtml"
<?xml version="1.0" encoding="utf-8"?>
<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>
<GetXhtml xmlns="http://tempuri.org/">
<url> http://localhost/waggleb/?Type=8AFCCCB9-93DC-421E-A617-92A990EC99A7</url>
</GetXhtml>
</soap:Body>
</soap:Envelope>
?>
Actual Full Request made by Nusoap:
POST /swindon/ppa/uat/contentserver/contentserver/contentserver.asmx HTTP/1.1
Host: www.qes24.com
User-Agent: NuSOAP/0.9.5 (1.123)
Connection: close
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/GetXhtml"
Content-Length: 516
<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header><content-type xsi:type="xsd:string">UTF-8</content-type></SOAP-ENV:Header><SOAP-ENV:Body><url xsi:type="xsd:string">http://localhost/waggleb/?Type=8AFCCCB9-93DC-421E-A617-92A990EC99A7</url></SOAP-ENV:Body></SOAP-ENV:Envelope>
Full response:
HTTP/1.1 200 OK
Date: Mon, 07 Feb 2011 10:50:25 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 329
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetXhtmlResponse xmlns="http://tempuri.org/"><GetXhtmlResult /></GetXhtmlResponse></soap:Body></soap:Envelope>
From the error that's being returned, I'd guess (but I can't be certain without knowing which API you're trying to use) that the problem is the method name. Perhaps it's cased incorrectly? Either way, this means that the server can't direct your SOAP request to the correct module.

Categories