I get the error message : "looks like we got no XML document" .
This is my php script :
<?php
$client = new SoapClient("http://ws-argos.cls.fr/argosDws/services/DixService?wsdl", array('trace' => 1, "exceptions" => 0));
$result = $client->getXml(array (
'username' => 'my username',
'password' => 'my password',
'platformId' => '1',
'nbPassByPtt' => 100,
'nbDaysFromNow' => 10,
'mostRecentPassages' => true
));
echo "====== REQUEST HEADERS =====" . PHP_EOL;
var_dump($client->__getLastRequestHeaders());
echo "========= REQUEST ==========" . PHP_EOL;
var_dump($client->__getLastRequest());
echo "========= RESPONSE =========" . PHP_EOL;
var_dump($result);
and this is the result of __getLastRequest() :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://service.dataxmldistribution.argos.cls.fr/types">
<SOAP-ENV:Body>
<ns1:xmlRequest>
<ns1:username>my username</ns1:username>
<ns1:password>my password</ns1:password>
<ns1:platformId>1</ns1:platformId>
<ns1:nbPassByPtt>100</ns1:nbPassByPtt>
<ns1:nbDaysFromNow>10</ns1:nbDaysFromNow>
<ns1:mostRecentPassages>true</ns1:mostRecentPassages>
</ns1:xmlRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
and this is how the request should look according to the documentation :
<soap:Envelope
xmlns:soap=”http://www.w3.org/2003/05/soap-envelope”
xmlns:typ=”http://service.dataxmldistribution.argos.cls.fr/types”>
<soap:Header/>
<soap:Body>
<typ:xmlRequest>
<typ:username>mturiot</typ:username>
<typ:password>qt</typ:password>
<typ:platformId>1</typ:platformId>
<typ:nbPassByPtt>2</typ:nbPassByPtt>
<typ:nbDaysFromNow>10</typ:nbDaysFromNow>
<typ:mostRecentPassages>true</typ:mostRecentPassages>
</typ:xmlRequest>
</soap:Body>
</soap:Envelope>
What am i doing wrong ? Any help is appreciated !
I came across the same problem, I turned to get solution in a different way.
It might not be the best way, but it works.
Source for the solution found here
$param = array(
'username'=>$username,
'password'=>$password,
'platformId'=>$platformId,
'nbDaysFromNow'=>20
);
$client = new SoapClient("http://ws-argos.cls.fr/argosDws/services/DixService?wsdl",
array('trace' => 1,
"exceptions" => 0,
'style'=> SOAP_DOCUMENT,
'use'=> SOAP_LITERAL));
$results = $client->getXml($param);
$results = $client->__getLastResponse();
//Handle BOM
$xml = explode("\r\n", $results);
//The resultant CDATA is at 6th tag
$response = preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $xml[6] );
//Get the CDATA content alone
$explode1 = explode("<return>", $response);
$xmlVar = explode("</return>", $explode1[1]);
$finalXML = $xmlVar[0];
//Convert string as XML
$xmlElem = simplexml_load_string('<xml>' . $finalXML . '</xml>');
echo $xmlElem;
Related
I've been failing to consume a soap webservice with soapClient /nusoap I believe the issue might be with my header but I'm not sure as the error I get back are pretty vague at times.
We've been able to get it to work in SoapUI, which adds some additional things to the header notably this:
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To>
Its being added in SoapUI automaticaly by checking: add default WSA:to under WS-A
inside the header it also has xmlns:wsa="http://www.w3.org/2005/08/addressing" I dont know how to correctly set this if possible.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://www.property24.com/services">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<ser:CredentialsHeader>
<!--Optional:-->
<ser:EMail>..</ser:EMail>
<!--Optional:-->
<ser:Password>..!</ser:Password>
<!--Optional:-->
<ser:UserGroupEmailId>1</ser:UserGroupEmailId>
</ser:CredentialsHeader>
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To></soap:Header>
<soap:Body>
<ser:FetchAgents>
<!--Optional:-->
<ser:agencyId>..</ser:agencyId>
</ser:FetchAgents>
</soap:Body>
</soap:Envelope>
I'm getting a bad request response which I believe could be due to the header
this is what I've tried:
$headerbody = array(
'EMail' => $username,
'Password' => $password,
'UserGroupEmailId'=> $groupId
);
$headers[] = new SoapHeader('https://www.exdev.property24.com/', 'wsa:Action', "http://www.property24.com/services/IP24ListingServiceWcf/$method");
$headers[] = new SoapHeader('https://www.exdev.property24.com/', 'wsa:To', "https://www.exdev.property24.com/Services/P24ListingService46.svc");
$headers[] = new SoapHeader('https://www.exdev.property24.com/', 'CredentialsHeader', $headerbody);
$client->__setSoapHeaders($headers);
and
$header_part = '<CredentialsHeader><EMail>....</EMail><Password>....</Password><UserGroupEmailId>1</UserGroupEmailId></CredentialsHeader>';
$header_part .= '<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/$method</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To>';
$soap_var_header = new SoapVar($header_part, XSD_ANYXML, null, null, null);
$soap_header = new SOAPHeader('http://www.w3.org/2005/08/addressing', 'wsa',
$soap_var_header);
$client->__setSoapHeaders($soap_header);
I've not had a lot of experience with Soap webservices and have been stuck on this for quite some time thanks guys
construct header object by concatenating with user credentials
$headerStr= '
<ser:CredentialsHeader>
<!--Optional:-->
<ser:EMail>'.$username.'</ser:EMail>
<!--Optional:-->
<ser:Password>'.$password.'</ser:Password>
<!--Optional:-->
<ser:UserGroupEmailId>'.$groupId.'</ser:UserGroupEmailId>
</ser:CredentialsHeader>
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To>
';
$header= new \SoapHeader('http://www.w3.org/2005/08/addressing',
'wsa',
new \SoapVar($headerStr, XSD_ANYXML),
true
);
then construct SoapClient and set headers and operation name with parameters
$soapclient = new SoapClient($serviceURL,$options);
$soapclient-> __setSoapHeaders($header);
parameters can be sent as dictionary but very important to chang "Request" to be identical to the same name in service contract
$param=array ("Request" => array('agencyId'=>'123'));
$response =$soapclient->FetchAgents( $param);
var_dump(json_encode($response));
echo '<br><br><br>';
$array = json_decode(json_encode($response), true);
print_r($array);
the complete code snippet will be
try {
$options = [
"soap_version" => SOAP_1_2, // SOAP_1_1
'trace' => 1,
'exception' => 1,
'keep_alive' => false,
'connection_timeout' => 500000
];
$headerStr = '
<ser:CredentialsHeader>
<!--Optional:-->
<ser:EMail>' . $username . '</ser:EMail>
<!--Optional:-->
<ser:Password>' . $password . '</ser:Password>
<!--Optional:-->
<ser:UserGroupEmailId>' . $groupId . '</ser:UserGroupEmailId>
</ser:CredentialsHeader>
<wsa:Action>http://www.property24.com/services/IP24ListingServiceWcf/FetchAgents</wsa:Action><wsa:To>https://www.exdev.property24.com/Services/P24ListingService46.svc</wsa:To></soap:Header>
';
$header = new \SoapHeader(
'http://www.w3.org/2005/08/addressing',
'ws',
new \SoapVar($headerStr, XSD_ANYXML),
true
);
$soapclient = new SoapClient($serviceURL, $options);
$soapclient->__setSoapHeaders($header);
$param = array('agencyId' => '123');
$response = $soapclient->FetchAgents($param);
// print the last XML request to compare with the working one in soapUI
echo "REQUEST:\n" . $soapclient->__getLastRequest() . "\n";
var_dump(json_encode($response));
echo '<br><br><br>';
$array = json_decode(json_encode($response), true);
print_r($array);
} catch (Exception $e) {
echo $e->getMessage();
}
How can I make Soap request using Curl php by using below soap format and url? I have tried avaliable solutions online and none of them worked out.
$soap_request = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:alisonwsdl" 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:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header>
<credentials>
<alisonOrgId>9ReXlYlpOThe24AWisE</alisonOrgId>
<alisonOrgKey>C2owrOtRegikaroXaji</alisonOrgKey>
</credentials>
</soap:Header>
<SOAP-ENV:Body>
<q1:login xmlns:q1="urn:alisonwsdl">
<email xsi:type="xsd:string">email</email>
<firstname xsi:type="xsd:string">fname</firstname>
<lastname xsi:type="xsd:string">lname</lastname>
<city xsi:type="xsd:string">city</city>
<country xsi:type="xsd:string">country</country>
<external_id xsi:type="xsd:string"></external_id>
</q1:login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
Url
https://alison.com/api/service.php?wsdl
Assuming you already have php_soap extension installed, you can access the SOAP API like this:
<?php
$client = new SoapClient('https://alison.com/api/service.php?wsdl', array(
'stream_context' => stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
))
));
You might want to define the header for authentication as well
$auth = array(
'alisonOrgId' => '9ReXlYlpOThe24AWisE',
'alisonOrgKey' => 'C2owrOtRegikaroXaji'
);
$header = new SoapHeader('https://alison.com/api/service.php?wsdl', 'credentials', $auth, false);
$client->__setSoapHeaders($header);
Then you can get the list of functions available
// Get function list
$functions = $client->__getFunctions ();
echo "<pre>";
var_dump ($functions);
echo "</pre>";
die;
Or call a function right away, like this:
// Run the function
$obj = $client->__soapCall("emailExists", array(
"email" => "test#email.com"
));
echo "<pre>";
var_dump ($obj);
echo "</pre>";
die;
After struggling for a week I was able to find something in this tutorial here on youtube https://www.youtube.com/watch?v=6V_myufS89A and I was able to send requests to the API successifuly, first read my xml format above before continuing with my solution
$options = array('trace'=> true, "exception" => 0);
$client = new \SoapClient('your url to wsdl',$options);
//if you have Authorization parameters in your xml like mine above use SoapVar and SoapHeader as me below
$params = new \stdClass();
$params->alisonOrgId = 'value here';
$params->alisonOrgKey = 'value here';
$authentication_parameters = new \SoapVar($params,SOAP_ENC_OBJECT);
$header = new \SoapHeader('your url to wsdl','credentials',$authentication_parameters);
$client->__setSoapHeaders(array($header));
print_r($client->__soapCall("Function here",'Function parameter here or left it as null if has no parameter'));
//or call your function by
print_r($client->yourFunction($function_parameters));
}
Hope this will help someone out there struggling with soap requests that contains authentication informations
Hy all!
I try to do DHL Express, but I get caught up very much with DHL not really wanting to help. So I would like to ask for help.
And since I do not get back tracking numbers for anything just underlying XML, so I would like to ask for help. Thank you very much for helping me.
What I try:
// The url of the service
$url = 'https://wsbexpress.dhl.com:443/sndpt/expressRateBook?WSDL';
// the soap operation which is called
$action = 'createShipmentRequest';
// the xml input of the service
$xmlrequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rat="http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/RateMsgRequest">
<soapenv:Header>
<wsse:Security soapenv:mustunderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:id="UsernameToken-5" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>*********</wsse:Username>
<wsse:Password type="PasswordText">*******</wsse:Password>
<wsse:Nonce encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">eUYebYfsjztETJ4Urt8AJw==</wsse:Nonce>
<wsu:Created>' . date('Y-m-d H:i:s') . '</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<soapenv:Header/>
<soapenv:Body>
<rat:RateRequest>
<RequestedShipment>
<DropOffType>REGULAR_PICKUP</DropOffType>
<Account>407194546</Account>
<Currency>EUR</Currency>
<UnitOfMeasurement>SI</UnitOfMeasurement>
<Ship>
<Shipper>
<StreetLines>Street number 22</StreetLines>
<City>City</City>
<PostalCode>111111</PostalCode>
<CountryCode>DE</CountryCode>
</Shipper>
<Recipient>
<StreetLines>Street number 22</StreetLines>
<City>City</City>
<PostalCode>111111</PostalCode>
<CountryCode>DE</CountryCode>
</Recipient>
</Ship>
<Packages>
<RequestedPackages number="1">
<Weight>
<Value>0.5</Value>
</Weight>
<Dimensions>
<Length>3</Length>
<Width>2</Width>
<Height>1</Height>
</Dimensions>
</RequestedPackages>
</Packages>
<ShipTimestamp>2018-07-18T08:00:00 GMT+0100</ShipTimestamp>
<Content>NON_DOCUMENTS</Content>
<PaymentInfo>DAP</PaymentInfo>
</RequestedShipment>
</rat:RateRequest>
</soapenv:Body>
</soapenv:Envelope>';
try {
// the soap client accepts options, we specify the soap version
// The trace option enables tracing of request so faults can be backtraced.
// The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault.
$opts = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$options = array(
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts),
'cache_wsdl' => WSDL_CACHE_NONE,
);
// create the soapclient and invoke __doRequest method
$client = new SoapClient($url, $options);
$output = $client->__doRequest($xmlrequest, $url, $action, 1);
} catch (SoapFault $fault) {
echo "<h2>SOAP Fault!</h2><p>";
echo "FaultCode: {$fault->faultcode} <br/>";
echo "FaultString: {$fault->faultstring} <br/>";
echo"</p/>";
}
echo "<h2>WSDL URL: </h2><p>";
echo $url;
echo "</p/>";
echo "<h2>Action: </h2><p>";
echo $action;
echo "</p/>";
echo "<h2>XMLRequest: </h2><p>";
echo $xmlrequest;
echo "</p/>";
if (!isset($output)) {
echo "<h2>SOAP Fault!</h2><p>";
echo "FaultCode: {$output->faultcode} <br/>";
echo "FaultString: {$output->faultstring} <br/>";
} else {
echo "<h2>Output: </h2><p>";
file_put_contents('dhl.xml', $output);
echo $output;
echo "</p/>";
}
Return: https://justpaste.it/52zqa (sorry too long)
The question is what do I get to get this xml?
Not returning the shipment number and returning the corresponding data
I think you are getting an WSDL because your URL is asking for it. Try removing the ?WSDL:
$url = 'https://wsbexpress.dhl.com:443/sndpt/expressRateBook';
References:
How to get the wsdl file from a webservice's URL
SOAP request returned wsdl instead of expected SOAP response
I am trying to send a SOAP request with a header and lots of parameters. This is not the first time I have used NuSOAP and have never had problems with it before. However what is new to me is I am including a header which may be what is causing the problem. Below is the code for my request:
$client = new nusoap_client($url,'wsdl','','','','');
$header =
"<ETGHeader>
<VersionRequest>1.0.0</VersionRequest>
<Originator>
<Signature>Signature</Signature>
<LoginData>
<Name>Name</Name>
<Password>Password</Password>
</LoginData>
</Originator>
</ETGHeader>";
$client->setHeaders($header);
$param = array(
"Settings" => array(
"param1" => "1",
"param2" => "2",
"param3" => "3"
)
);
// Call the WebService
$result = $client->call('GetListVehicleType', array('parameters' => $param), '', '', false, true);
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
Here is the request that is being sent:
<?xml version="1.0" encoding="ISO-8859-1"?><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><ETGHeader>
<VersionRequest>1.0.0</VersionRequest>
<Originator>
<Signature>Signature</Signature>
<LoginData>
<Name>Name</Name>
<Password>Password</Password>
</LoginData>
</Originator>
</ETGHeader></SOAP-ENV:Header><SOAP-ENV:Body><GetListVehicleType xmlns="http://url"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
None of my parameters are being included in the request.
Any help much appreciated
Alex
Might be a problem with NuSOAP, recoded it using PHP's inbuilt SoapClient and got it working.
I'm trying to pass a fairly complex parameter string which I have an XML example of and I'm trying to encode it properly using PHP. The example request I was given is this:
<?xml version="1.0" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body xmlns:tns="http://172.16.53.121/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://www.amtrak.com/TrainStatus/2006/01/01" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsdns1="http://www.amtrak.com/schema/2006/01/01" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<TrainStatusRQ xmlns="http://www.amtrak.com/schema/2006/01/01" xmlns:ota="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.0" EchoToken="TestToken">
<POS>
<ota:Source>
<ota:RequestorID Type="WAS" ID="ToBeProvidedByAmtrak">
<ota:CompanyName CompanyShortName="ToBeProvidedByAmtrak"/>
</ota:RequestorID>
</ota:Source>
</POS>
<TrainStatusInfo TrainNumber="3">
<TravelDate>
<ota:DepartureDateTime>2006-01-07</ota:DepartureDateTime>
</TravelDate>
<Location LocationCode="KNG"/>
</TrainStatusInfo>
</TrainStatusRQ>
</SOAP-ENV:Body>
And I'm going to call it use it like this
try
{
$client = new SoapClient($soapURL, $soapOptions);
$trainStatus = $client->processTrainStatus($TrainStatusRQ);
var_dump($trainStatus);
//var_dump($client->__getTypes());
}
catch(SoapFault $e)
{
echo "<h2>Exception Error!</h2></b>";
echo $e->faultstring;
}
Its the encoding of $TrainStatusRQ that I cant seem to figure out since there are attributes and multilevel parameters. This is as close as I have gotten.
$RQStruc = array(
"POS" => array(
"Source"=> array(
"RequestorID" => array(
'type'=>'WAS',
'ID'=>'0',
'CompanyName'=>array(
'CompanyShortName'=>"0"
)
)
)
),
"TrainStatusInfo" => array(
'TrainNumber'=>$TrainNumber,
'TravelDate' => array(
'DepartureDateTime' => array(
'_' => $today
)
),
"Location" => array(
'LocationCode'=>$LocationCode
)
)
);
$TrainStatusRQ = new SoapVar($RQStruc, XSD_ANYTYPE, "TrainStatusRQ","http://www.amtrak.com/schema/2006/01/01" );
I had similar problems when dealing with a .NET service.
What I ended up with was assembling the structure as plain string.
$p = array();
foreach ($items as $item) {
$p[] = "
<MyEntity class='entity'> // the attribute was required by .NET
<MyId>{$item->SomeID}</MyId>
<ItemId>{$item->ItemId}</ItemId>
<Qty>{$item->Qty}</Qty>
</MyEntity>";
}
$exp = implode("\n", $p);
$params['MyEntity'] = new \SoapVar("<MyEntity xmlns='http://schemas.microsoft.com/dynamics/2008/01/documents/MyEntity'>$exp</MyEntity>", XSD_ANYXML);
Worked without problems.
Passing in the XML as a string with XSD_ANYXML as the type was the answer. I also needed to leave out the third and fourth parameters in the SoapVar() function call.
$XML = '<TrainStatusRQ xmlns="http://www.amtrak.com/schema/2006/01/01" xmlns:ota="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.0" EchoToken="TestToken">
<POS>
<ota:Source>
<ota:RequestorID Type="WAS" ID="foo">
<ota:CompanyName CompanyShortName="bat"/>
</ota:RequestorID>
</ota:Source>
</POS>
<TrainStatusInfo TrainNumber="'.$TrainNumber.'">
<TravelDate>
<ota:DepartureDateTime>'.$Today.'</ota:DepartureDateTime>
</TravelDate>
</TrainStatusInfo>
</TrainStatusRQ>';
$TrainStatusRQ = new SoapVar($XML,XSD_ANYXML);