I'm trying to connect to Royal Mail shipping API, but I'm receiving the famous Could not connect to host.
$api_password = "****";
$api_username = "****";
$api_application_id = "****";
$api_service_type = "D";
$api_service_code = "SD1";
$api_service_format = "";
$api_certificate_passphrase = "****";
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz(copy from sample);
$passwordDigest = zyz(copy from sample);
$ENCODEDNONCE = zyz(copy from sample);
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['local_cert'] = "CA2+Splash+Felipe+RM10001654+usr.p12";
$soapclient_options['passphrase'] = $api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = '****';
//launch soap client
$client = new SoapClient("SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
(setting header)
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
(setting request part)
if($api_service_enhancements != "") {
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $api_service_enhancements)));
}
//try make the call
try {
$response = $client->__soapCall('createShipment', array($request), array('soapaction' => '***api-link***') );
} catch (Exception $e) {
//catch the error message and echo the last request for debug
echo $e->getMessage();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
die;
}
Is it correct the way I'm setting the connection and the local cert?
Is any information I'm missing?
Thanks & Regards
Follow my final code :) this one works for sure. Even have the retry in case the server is buzy, enjoy.
<?php
//ini_set('soap.wsdl_cache_enabled', '1');
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
class royalmaillabelRequest
{
private $apiapplicationid = "insert urs";
private $api_password = "insert urs";
private $api_username = "insert urs"; //"rxxxxxAPI"
private $api_certificate_passphrase = "insert urs";
private $locationforrequest = 'https://api.royalmail.com/shipping/onboarding'; //live 'https://api.royalmail.com/shipping' onbording 'https://api.royalmail.com/shipping/onboarding'
private $api_service_enhancements = "";
private function preparerequest(){
//PASSWORD DIGEST
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz(copy from sample);
$passwordDigest = nyz(copy from sample);
$ENCODEDNONCE = (copy from sample);
//SET CONNECTION DETAILS
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['stream_context'] = stream_context_create(
array('http'=>
array(
'protocol_version'=>'1.0'
, 'header' => 'Connection: Close'
)
)
);
$soapclient_options['local_cert'] = dirname(__FILE__) . "/certificate.pem";
$soapclient_options['passphrase'] = $this->api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = $this->locationforrequest;
$soapclient_options['soap_version'] = 'SOAP_1_1';
//launch soap client
$client = new SoapClient(dirname(__FILE__) . "/SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
//headers needed for royal mail//D8D094Fd2716E3Es142588808s317
$HeaderObjectXML = '<wsse:Security 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">
<wsse:UsernameToken wsu:Id="UsernameToken-D8D094FC22716E3EDE14258880881317">
<wsse:Username>'.$this->api_username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$passwordDigest.'</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$ENCODEDNONCE.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
//push the header into soap
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
return $client;
}
public function CreateShippiment($data){
$request = $this->buildCreateshippiment($data);
$type = 'createShipment';
return $this->makerequest($type, $request);
}
public function PrintLabel($shipmentNumber,$order_tracking_id){
$time = gmdate('Y-m-d\TH:i:s');
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $order_tracking_id
)
),
'shipmentNumber' => $shipmentNumber,
'outputFormat' => 'PDF',
);
$type = 'printLabel';
$response = $this->makerequest($type, $request);
return $response->label;
}
private function makerequest($type, $request){
$client = $this->preparerequest();
$response = false;
$times = 1;
while(true){
try {
$response = $client->__soapCall( $type, array($request), array('soapaction' => $this->locationforrequest) );
// echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
} catch (Exception $e) {
print_r($e);
if($e->detail->exceptionDetails->exceptionCode == "E0010" && $times <= 25){
sleep(1.5);
$times++;
continue;
}else{
echo $e->getMessage();
echo "<pre>";
print_r($e->detail);
echo $client->__getLastResponse();
echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
}
}
break;
}
return $response;
}
private function buildCreateshippiment($data2) {
$time = gmdate('Y-m-d\TH:i:s');
$data = new ArrayObject();
foreach ($data2 as $key => $value)
{
$data->$key = $value;
}
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $data->order_tracking_id
)
),
'requestedShipment' => array(
'shipmentType' => array('code' => 'Delivery'),
'serviceOccurrence' => 1,
'serviceType' => array('code' => $data->api_service_type),
'serviceOffering' => array('serviceOfferingCode' => array('code' => $data->api_service_code)),
'serviceFormat' => array('serviceFormatCode' => array('code' => $data->api_service_format)),
'shippingDate' => date('Y-m-d'),
'recipientContact' => array('name' => $data->shipping_name, 'complementaryName' => $data->shipping_company),
'recipientAddress' => array('addressLine1' => $data->shipping_address1, 'addressLine2' => $data->shipping_address2, 'postTown' => $data->shipping_town, 'postcode' => $data->shipping_postcode),
'items' => array('item' => array(
'numberOfItems' => $data->order_tracking_boxes,
'weight' => array( 'unitOfMeasure' => array('unitOfMeasureCode' => array('code' => 'g')),
'value' => $data->order_tracking_weight,
)
)
),
//'signature' => 0,
)
);
if($data->api_service_enhancements == 6 && $data->api_service_type == 1){
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $data->api_service_enhancements)));
}
return $request;
}
}
docs.oasis-open.org is slow and doesn't respond in time.
Download oasis-200401-wss-wssecurity-utility-1.0.xsd and modify ShippingAPI_V2_0_8.wsdl to use local version.
Your location looks wrong..
$soapclient_options['location'] = '****';
Shouldn't this look like this..
$soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
Related
I hope I can help if possible, I can have a backend in Laravel and I need to consume some SOAP web services, for this I am using the native SoapClient() class. I'm getting this error:
SOAP ERROR: Analysis scheme: you cannot import the scheme from http://[redacted]?xsd=xsd0
I cannot display the URL because it is a private but external server of the company. Here is my code:
public function getCotizacion(){
// phpinfo();
$Empresa = $this->set_Empresa();
$Sistema = $this->set_Sistema();
$Direcciones = $this->set_Direcciones();
$namespace = "http://[redacted]";
$IdConfiguracion = $this->set_IdConfiguracion();
$Solicitante = $this->set_Solicitante();
$FechaRegistro = date("c");
$WCFBroker = $this->set_WCFBroker();
$options = array(
"trace" => 1,
"encoding" => "UTF-8",
"verifypeer" => false,
"verifyhost" => false,
"proxy_port" => 7801,
"soap_version" => SOAP_1_2,
"trace" => 1,
"exceptions" => true,
"cache_wsdl"=>WSDL_CACHE_NONE
);
// SOAP client
$soapClient = new \SoapClient($WCFBroker, $options);
$auth = array(
'Empresa' => (string) $Empresa,
'Sistema' => (string) $Sistema,
'Direcciones' => (string) $Direcciones
);
$header = new \SoapHeader($namespace, 'SeguridadHeaderElement', $auth, false);
$soapClient->__setSoapHeaders($header);
// nodos de arreglo body
$request0 = new stdClass();
$request0->FechaHora = $FechaRegistro;
$request1 = new stdClass();
$request1->ConsecutivoConfiguracion = $IdConfiguracion;
$request1->Solicitante = $Solicitante;
$request1->Parametros = new \SoapVar($Trama, XSD_ANYXML);
$parameters = new stdClass();
$parameters->InfoSolicitud = array('InfoTransaccion' => $request0, 'Cotizacion' => $request1);
$Info = array();
try {
$Info['Info'] = $soapClient->CotizarPoliza($parameters);
} catch (SoapFault $fault) {
$Info['Info'] = $fault;
}
$Info['request']['headers'] = $soapClient->__getLastRequestHeaders();
$Info['request']['body'] = $soapClient->__getLastRequest();
$Info['response']['headers'] = $soapClient->__getLastResponseHeaders();
$Info['response']['body'] = $soapClient->__getLastResponse();
return $Info;
}
The error paints this line as the one that is failing:
$soapClient = new \SoapClient($WCFBroker, $options);
What's going wrong?
I'm new on Soap\NuSoap
I can connect to server site but from server send data back to client i can not get data in array to show client site. I have to test to get data and send data back to other database. I have to get in array.
it's show error
XML error parsing SOAP payload on line 2: Invalid document end
I can't fix it by myself. please help.
This is my client.php
include("lib/nusoap.php");
$client = new nusoap_client("http://192.168.20.3/soap_server/webservice.php?wsdl");
$client->soap_defencoding = 'utf-8';
$client->encode_utf8 = false;
$client->decode_utf8 = false;
$params = array(
'strName' => $_POST["strName"],
);
$result = $client->call("resultCustomer",$params);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
print_r($result);
And this is server.php
require_once("lib/nusoap.php");
//Define our namespace
$namespace = "http://localhost/soap_server/webservice.php";
//Create a new soap server
$server = new soap_server();
//Configure our WSDL
$server->configureWSDL("getCustomer");
$server->wsdl->schemaTargetNamespace = $namespace;
$server->soap_defencoding = 'utf-8';
$server->encode_utf8 = false;
$server->decode_utf8 = false;
//Register our method and argument parameters
$varname = array(
'strName' => "xsd:string"
);
//Add ComplexType
$server->wsdl->addComplexType(
'ArrayOfString',
'complexType',
'array',
'',
'',
array(
'id_user' => array('name' => 'id_user', 'type' => 'xsd:string'),
'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
'username' => array('name' => 'username', 'type' => 'xsd:string'),
'lastname' => array('name' => 'lastname', 'type' => 'xsd:string')
)
);
//Add ComplexType
$server->wsdl->addComplexType(
'ArrayOfString',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]')
),
'tns:DataList'
);
// Register service and method
$server->register('resultCustomer',$varname, array('return' => 'tns:ArrayOfString'));
function resultCustomer($strName)
{
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("qpt-test");
$strSQL = "SELECT * FROM qpt_user where firstname like '%".$strName."%'";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
return $resultArray;
}
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
I sent request to webservice like this :
$transaction = new Transaction();
$transaction->amount = $amount;
$transaction->order_id = $orderId;
$transaction->status = 0;
$transaction->additional_data = $additionalData;
$transaction->type = 1;
$transaction->ip = Request::getClientIp();
$transaction->save();
$soap = new nusoap_client(self::$request_url);
$fields = array(
'terminalId' => self::$terminalId,
'userName' => self::$username,
'userPassword' => self::$password,
'orderId' => $transaction->order_id,
'amount' => $amount,
'localDate' => date('Ymd'),
'localTime' => date('His'),
'additionalData' => $additionalData,
'callBackUrl' => self::$callBackUrl,
'payerId' => 0,
);
$response = $soap->call('bpPayRequest', $fields, 'http://interfaces.core.sw.bps.com/');
but i get exception in line 2125 in nusoap.php :
Array to string conversion
exception thrown from :
// TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
foreach(curl_getinfo($this->ch) as $k => $v){
$err .= "$k: $v<br>";
}
$this->debug($err);
I'm trying to send some data to Royal Mail API, but i receive a message saying: E0004 Failed Schema Validation. Follow the code i used to create the request:
$api_password = "xxxx";
$api_username = "xxx#xxx.comAPI";
$api_application_id = "xxxxxx";
$api_service_type = "D";
$api_service_code = "SD1";
$api_service_format = "";
$api_certificate_passphrase = "xxxxx";
$api_service_enhancements = "";
$data = new ArrayObject();
$data->order_tracking_id = "";
$data->shipping_name = "Felipe";
$data->shipping_company = "splash";
$data->shipping_address1 = "23, St johns road";
$data->shipping_address2 = "";
$data->shipping_town = "london";
$data->shipping_postcode = "NW11 0PE";
$data->order_tracking_boxes = "0";
$data->order_tracking_weight = "1500";
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz . xyz . pack("H**", sha1($api_password));
$passwordDigest = base64_encode(pack('ZH**',sha1($nonce_date_pwd)));
$ENCODEDNONCE = base64_encode($nonce);
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['local_cert'] = "certificate.pem";
$soapclient_options['passphrase'] = $api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
$soapclient_options['soap_version'] = 'SOAP_1_1';
//'soap_version' => SOAP_1_2,
//launch soap client
$client = new SoapClient("SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
// print_r($client);
//headers needed for royal mail
$HeaderObjectXML = '<wsse:Security 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">
<wsse:UsernameToken wsu:Id="UsernameToken-xxxxxx">
<wsse:Username>'.$api_username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$passwordDigest.'</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$ENCODEDNONCE.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
//push the header into soap
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
//build the request
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2.0',
'identification' => array(
'applicationId' => $api_application_id,
'transactionId' => $data->order_tracking_id
)
),
'requestedShipment' => array(
'shipmentType' => array('code' => 'Delivery'),
'serviceOccurence' => '1',
'serviceType' => array('code' => $api_service_type),
'serviceOffering' => array('serviceOfferingCode' => array('code' => $api_service_code)),
'serviceFormat' => array('serviceFormatCode' => array('code' => $api_service_format)),
'shippingDate' => date('Y-m-d'),
'recipientContact' => array('name' => $data->shipping_name, 'complementaryName' => $data->shipping_company),
'recipientAddress' => array('addressLine1' => $data->shipping_address1, 'addressLine2' => $data->shipping_address2, 'postTown' => $data->shipping_town, 'postcode' => $data->shipping_postcode),
'items' => array('item' => array( 'numberOfItems' => $data->order_tracking_boxes, 'weight' => array( 'unitOfMeasure' => array('unitOfMeasureCode' => array('code' => 'g')), 'value' => ($data->order_tracking_weight) //weight of each individual item
)
)
)
)
);
$body = new SoapVar( $request, SOAP_ENC_OBJECT );
//if any enhancements, add it into the array
if($api_service_enhancements != "") {
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $api_service_enhancements)));
}
try {
$response = $client->__soapCall( 'createShipment', array($request), array('soapaction' => 'https://api.royalmail.com/shipping/onboarding') );
print_r($response);
} catch (Exception $e) {
//catch the error message and echo the last request for debug
//print_r($e);
echo $e->getMessage();
echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
// die;
}
Follow the Request the code is creating:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.royalmailgroup.com/integration/core/V1" xmlns:ns2="http://www.royalmailgroup.com/api/ship/V2" xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<SOAP-ENV:Header>
<wsse:Security 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">
<wsse:UsernameToken wsu:Id="UsernameToken-xxxxxx">
<wsse:Username>xxx#xxxxx</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">ztyoDZ0RtlCehYvlhEYYCOCXt0CY=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MjA5MzA5jNjU1MQ==</wsse:Nonce>
<wsu:Created>2015-03-17T10:56:02Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:createShipmentRequest>
<ns2:integrationHeader><ns1:dateTime>2015-03-17T10:56:02</ns1:dateTime><ns1:version>2.0</ns1:version><ns1:identification><ns1:applicationId>xxxxx</ns1:applicationId><ns1:transactionId>730222611</ns1:transactionId></ns1:identification></ns2:integrationHeader>
<ns2:requestedShipment>
<ns2:shipmentType><code>Delivery</code></ns2:shipmentType>
<ns2:serviceType><code>D</code></ns2:serviceType>
<ns2:serviceOffering><serviceOfferingCode><code>SD1</code></serviceOfferingCode></ns2:serviceOffering>
<ns2:serviceFormat><serviceFormatCode><code></code></serviceFormatCode></ns2:serviceFormat>
<ns2:shippingDate>2015-03-17</ns2:shippingDate>
<ns2:recipientContact>
<ns2:name>Felipe</ns2:name>
<ns2:complementaryName>splash</ns2:complementaryName>
</ns2:recipientContact>
<ns2:recipientAddress>
<addressLine1>27, St johns road</addressLine1>
<addressLine2></addressLine2>
<postTown>london</postTown>
<postcode>NW11 0PE</postcode>
</ns2:recipientAddress>
<ns2:items>
<ns2:item>
<ns2:numberOfItems>0</ns2:numberOfItems>
<ns2:weight><unitOfMeasure><unitOfMeasureCode><code>g</code></unitOfMeasureCode></unitOfMeasure><value>1500</value></ns2:weight>
</ns2:item>
</ns2:items>
</ns2:requestedShipment></ns2:createShipmentRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>
Follow the example request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.royalmailgroup.com/integration/core/V1" xmlns:v2="http://www.royalmailgroup.com/api/ship/V2">
<soapenv:Header><wsse:Security 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"><wsse:UsernameToken wsu:Id="UsernameToken-xxxxxxxxxxxxxx"><wsse:Username>xxxx#xxx.comAPI</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">gShxrkDCihB04r5iG+xA+p7aqMU=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">Kxv2sk4hXnvAHLbOVIsuvw==</wsse:Nonce><wsu:Created>2015-03-09T08:01:28.132Z</wsu:Created></wsse:UsernameToken></wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v2:createShipmentRequest>
<v2:integrationHeader>
<v1:dateTime>2015-03-08T08:52:03</v1:dateTime>
<v1:version>2</v1:version>
<v1:identification>
<v1:applicationId>xxxxxxxxx</v1:applicationId>
<v1:transactionId>730222611</v1:transactionId>
</v1:identification>
</v2:integrationHeader>
<v2:requestedShipment>
<v2:shipmentType>
<code>Delivery</code>
</v2:shipmentType>
<v2:serviceOccurrence>1</v2:serviceOccurrence>
<v2:serviceType>
<code>D</code>
</v2:serviceType>
<v2:serviceOffering>
<serviceOfferingCode>
<code>SD1</code>
</serviceOfferingCode>
</v2:serviceOffering>
<v2:serviceFormat>
<serviceFormatCode/>
</v2:serviceFormat>
<v2:signature>1</v2:signature>
<v2:shippingDate>2015-02-09</v2:shippingDate>
<v2:recipientContact>
<v2:name>Mr Tom Smith</v2:name>
<v2:complementaryName>Department 98</v2:complementaryName>
<v2:telephoneNumber>
<countryCode>0044</countryCode>
<telephoneNumber>07801123456</telephoneNumber>
</v2:telephoneNumber>
<v2:electronicAddress>
<electronicAddress>tom.smith#royalmail.com</electronicAddress>
</v2:electronicAddress>
</v2:recipientContact>
<v2:recipientAddress>
<addressLine1>3 Vantage Walk</addressLine1>
<postTown>Hastings</postTown>
<postcode>TN38 0YP</postcode>
<country>
<countryCode>
<code>GB</code>
</countryCode>
</country>
</v2:recipientAddress>
<v2:items>
<v2:item>
<v2:numberOfItems>1</v2:numberOfItems>
<v2:weight>
<unitOfMeasure>
<unitOfMeasureCode>
<code>g</code>
</unitOfMeasureCode>
</unitOfMeasure>
<value>100</value>
</v2:weight>
</v2:item>
</v2:items>
<v2:customerReference>CustSuppRef1</v2:customerReference>
<v2:senderReference>SenderReference1</v2:senderReference>
</v2:requestedShipment>
</v2:createShipmentRequest>
</soapenv:Body>
</soapenv:Envelope>
I'm really stuck on it, nothing i try looks to work. I feel like it's something really small that I'm not been able to find.
Any help would be great.
Thanks
I'm trying to create a webservice with PHP and nuSoap but everytime I try to execute it I'm getting the error:
XML error parsing SOAP payload on line 1: Not well-formed (invalid token)
Can anyone see what's wrong?
service.php
<?php
require 'lib/nusoap.php';
$server = new nusoap_server();
$server->configureWSDL("casamitger" . "urn:casamitger");
$server->wsdl->schemaTargetNamespace = 'urn:casamitger';
include 'functions.php';
//getAvailabilities
$server->wsdl->addComplexType('Availabilities','complexType','struct','all','',array(
'StartDate' => array('name' => 'StartDate', 'type' => 'xsd:date'),
'EndDate' => array('name' => 'EndDate', 'type' => 'xsd:date'),
'State' => array('name' => 'State', 'type' => 'xsd:string'),
));
$server->wsdl->addComplexType('ArrayOfAvailabilities', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Availabilities[]')), 'tns:Availabilities');
$server->register(
'getAvailabilities',
array(
"SessionID" => 'xsd:string',
"AccommodationId" => 'xsd:integer'
),
array("return" => 'tns:ArrayOfAvailabilities')
);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
functions.php
function getAvailabilities($sessionID, $accommodation_code) {
$connection = mysqli_connect("localhost", "root", "", "casamitger");
if (authenticate($sessionID)) {
$user = getUser($sessionID);
$query = mysqli_query($connection, "SELECT count(AccommodationId) c FROM UserAccommodations WHERE AccommodationId = '$accommodation_code' AND CompanyId = '$user'") or die();
$row = mysqli_fetch_object($query);
$count = $row->c;
if ($count > 0) {
$query = mysqli_query($connection, "SELECT StartDate,EndDate,State FROM Availabilities WHERE AccommodationId = '$accommodation_code'") or die();
$n = 0;
while ($row = mysqli_fetch_object($query)) {
$result[$n]['StartDate'] = $row->StartDate;
$result[$n]['EndDate'] = $row->EndDate;
$result[$n]['State'] = $row->State;
$n++;
}
return $result;
}
}
}
and the client.php
<?php
require 'lib/nusoap.php';
include 'functions.php';
$sessionid = '1234';
$accommodation_code = '83081';
$client = new nusoap_client("http://192.168.8.155:8090/ws/service.php?wsdl");
$availabilities = $client->call(
'getAvailabilities',
array(
"SessionID" => "$sessionid",
"AccommodationId" => "$accommodation_code",
)
);
if ($client->fault) {
echo 'Fault';
} else {
$err = $client->getError();
if ($err) {
echo $err;
} else {
print_r($servicetypes);
}
}
?>
If I call the method getAvailabilities() directly it works but it doesn't through the web service, any help will be appreciated, thanks.