im trying to use the php soap client to make a soap call, but it keeps giving me " Request cannot be blank. Please provide request details. ". What am I doing wrong here?
$username = 'myusername_example';
$password = '123456787';
$url = "http://trail.dexceldesigns.com/m2m/APIwsdls/SessionService/SessionService.wsdl";
$soapclient = new \SoapClient($url);
try{
$params = array(
'Username' => $username,
'Password' => $password
);
$response = $soapclient->LogIn($params);
}
catch(\SoapFault $fault)
{
echo '<br/>'.$fault->getLine();
echo '<br/>Message: '.$fault->getMessage();
echo '<br/>Trace: '.$fault->getTraceAsString();
echo '<br/><br/>'.$fault->getCode();
echo '<br/><br/>'.$fault->getFile();
}
var_dump($soapclient->__getLastRequest());
EDIT:
Output for var_dump($soapclient->__getLastRequest()); is always coming as NULL
EDIT:2 (this is the request according to the documentation)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.datacontract.org/2004/07/NPhase.UnifiedWebService.APIs.v2.Contract.SessionService" xmlns:ns2="http://nphase.com/unifiedwebservice/v2">
<SOAP-ENV:Body>
<ns2:LogIn>
<ns2:Input>
<ns1:Username>?</ns1:Username>
<ns1:Password>?</ns1:Password>
</ns2:Input>
</ns2:LogIn>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Related
I've been searching around for a solution to my problem, but to no avail. I'm trying to send a soap request through a Wordpress plugin using the following:
function soapRequest($soapUsername, $soapNonce, $soapDateTime, $soapPassword) {
$wsdl = 'http://www.beautyfort.com/api/wsdl/v2/wsdl.wsdl';
$trace = true;
$exceptions = false;
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
// Must be a stdClass (and not an array)
$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Nonce = $soapNonce;
$auth->Created = $soapDateTime;
$auth->Password = $soapPassword;
$header = new SoapHeader('http://www.beautyfort.com/api/', 'AuthHeader', $auth);
$client->__setSoapHeaders($header);
$xml_array['TestMode'] = 'true';
$xml_array['StockFileFormat'] = 'JSON';
$xml_array['SortBy'] = 'StockCode';
try {
$response = $client->GetStockFile($xml_array);
}
catch (Exception $e) {
log_me("Error!");
log_me($e -> getMessage());
log_me('Last response: '. $client->__getLastResponse());
}
log_me('Last request: '. $client->__getLastRequest());
log_me($response);
}
This produces the following request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.beautyfort.com/api/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:Username>joetest</ns1:Username>
<ns1:Nonce>htflFfIKM4</ns1:Nonce>
<ns1:Created>2019-02-09T10:13:51.000Z</ns1:Created>
<ns1:Password>NGFjYTJiNzJmOWY2MzBmY2M2MjJkNjg1MDgyMWRjMzQxOGY1YTNjYQ==</ns1:Password>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetStockFileRequest>
<ns1:TestMode>true</ns1:TestMode>
<ns1:StockFileFormat>JSON</ns1:StockFileFormat>
<ns1:SortBy>StockCode</ns1:SortBy>
</ns1:GetStockFileRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And I get an invalid credentials error. I've also been testing in SoupUI and the following request works:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://www.beautyfort.com/api/">
<soapenv:Header>
<api:AuthHeader>
<api:Username>joetest</api:Username>
<api:Nonce>tJrsRlQt6i</api:Nonce>
<api:Created>2019-02-06T23:34:11.000Z</api:Created>
<api:Password>ZTBhMmE5OGY4YTNlZWIzZTE0ZTc2ZjZiZDBhM2RhMjJmNzAxNzYwZA==</api:Password>
</api:AuthHeader>
</soapenv:Header>
<soapenv:Body>
<api:GetStockFileRequest>
<api:TestMode>true</api:TestMode>
<api:StockFileFormat>JSON</api:StockFileFormat>
<!--Optional:-->
<api:FieldDelimiter>,</api:FieldDelimiter>
<!--Optional:-->
<api:StockFileFields>
<!--1 or more repetitions:-->
<api:StockFileField>StockCode</api:StockFileField>
<api:StockFileField>Category</api:StockFileField>
<api:StockFileField>Brand</api:StockFileField>
<api:StockFileField>Collection</api:StockFileField>
<api:StockFileField>Category</api:StockFileField>
</api:StockFileFields>
<api:SortBy>StockCode</api:SortBy>
</api:GetStockFileRequest>
</soapenv:Body>
</soapenv:Envelope>
Now the only differences I can see (apart from the optional fields) is the names of the namespace, and the use of the Xml tag at the top of the request. Both of these shouldn't matter right? I'd really appreciate your help on this as I've been scratching my head for ages.
Thank you in advance!
Your perfect just need to set UTC timezone and secret format like below:
base64 encoded(sha1(Nonce . Created . Secret))
I have the below SOAP XML, Im trying to access the vehicle details with the soap header authentication. I have tried the below code. I think, Im missing something on this. Can u help
SOAPAction: "http://abcddetails.org/getVehicleDetails"
<?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:Header>
<UserIdentifierSoapHeaderIn xmlns="http://abcddetails.org/">
<UserName>string</UserName>
<Password>string</Password>
</UserIdentifierSoapHeaderIn>
</soap:Header>
<soap:Body>
<getVehicleDetails xmlns="http://abcddetails.org/">
<request>
<SystemCode>int</SystemCode>
<UserID>string</UserID>
<PlateInfo>
<PlateNo>long</PlateNo>
<PlateOrgNo>long</PlateOrgNo>
<PlateColorCode>int</PlateColorCode>
</PlateInfo>
<ChassisNo>string</ChassisNo>
</request>
</getVehicleDetails>
</soap:Body>
PHP code along with the SOAP Header, I have created as the below.
<?php
$wsdl = "http://abcddetails.org/InspectionServices.asmx?WSDL";
$client = new SoapClient($wsdl, array('trace'=>1)); // The trace param will show you errors stack
$auth = array(
'Username'=>'XXXXX',
'Password'=>'XXXXX',
);
$header = new SOAPHeader($wsdl, 'UserIdentifierSoapHeaderIn', $auth);
$client->__setSoapHeaders($header);
// web service input params
$request_param = array(
"SystemCode" => 4,
"UserID" => "TEST",
"ChassisNo" => '1N4AL3A9XHC214925'
);
$responce_param = null;
try
{
$responce_param = $client->getVehicleDetails($request_param);
//$responce_param = $client->call("webservice_methode_name", $request_param); // Alternative way to call soap method
}
catch (Exception $e)
{
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
print_r($responce_param);
?>
Can u guide if anything I have written wrong here in this.
You can use the __soapCall method like this:
$result = $client->__soapCall('webserviceMethodeName', ['parameters' => $params]);
In your case a soap action would be invoked like this:
$responce_param = $client->__soapCall('getVehicleDetails', ['parameters' => $request_param]);
Read more
I'm trying to login to an API using built-in soap functions of PHP. I got a result like this.
[LoginResult]=> false,
[ErrorMsg] => Login failed with the reason : The security object is invalid
This is what required by the API provider.
<?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>
<Login xmlns="http://tempuri.org/Example/Service1">
<objSecurity>
<WebProviderLoginId>test</WebProviderLoginId>
<WebProviderPassword>test</WebProviderPassword>
<IsAgent>false</IsAgent>
</objSecurity>
<OutPut />
<ErrorMsg />
</Login>
</soap:Body>
</soap:Envelope>
&, here is what I was able to produce using functions.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1">
<SOAP-ENV:Body>
<ns1:Login>
<objSecurity>
<WebProviderLoginId>test</WebProviderLoginId>
<WebProviderPassword>test</WebProviderPassword>
<IsAgent>false</IsAgent>
</objSecurity>
<OutPut/>
<ErrorMsg/>
</ns1:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here is the code I used to send the request.
<?php
class objSecurity {
function objSecurity($s, $i, $f) {
$this->WebProviderLoginId = $s;
$this->WebProviderPassword = $i;
$this->IsAgent = $f;
}
}
class nextObject {
function nextObject($objSecurity) {
$this->objSecurity=$pobjSecurity;
$this->OutPut=NULL;
$this->ErrorMsg=NULL;
}
}
$url = 'http://example.com/sampleapi/test.asmx?WSDL';
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));
$struct = new objSecurity('test', 'test', false);
$data = new nextObject($struct);
$soapstruct2 = new SoapVar($data, SOAP_ENC_OBJECT);
print_r(
$client->__soapCall(
"Login",
array(new SoapParam($soapstruct2, "inputStruct"))
)
);
echo $client->__getLastRequest();
?>
These are the differences I found.
In my request xmlns:xsi is missing.
Requirement starts with <soap:Envelope, But my request starts with <SOAP-ENV:Envelope.
There is an extra xmlns:ns1 in my request.
& The function name tag starts with ns1:.
Please help me to make my request into the required format.
I don't know much about the SOAP and I'm using PHP version 5.3.13 with CakePHP 2.3.0. Sorry, for my bad English.
Here is the solution. :)
<?php
$url = 'http://example.com/sampleapi/test.asmx?WSDL';
$client = new SoapClient($url, array("soap_version" => SOAP_1_1,"trace" => 1));
$user_param = array (
'WebProviderLoginId' => "test",
'WebProviderPassword' => "test",
'IsAgent' => false
);
$service_param = array (
'objSecurity' => $user_param,
"OutPut" => NULL,
"ErrorMsg" => NULL
);
print_r(
$client->__soapCall(
"Login",
array($service_param)
)
);
echo $client->__getLastRequest();
?>
& the request was:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1">
<SOAP-ENV:Body>
<ns1:Login>
<ns1:objSecurity>
<ns1:WebProviderLoginId>test</ns1:WebProviderLoginId>
<ns1:WebProviderPassword>test</ns1:WebProviderPassword>
<ns1:IsAgent>false</ns1:IsAgent>
</ns1:objSecurity>
</ns1:Login>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Thanks to this link.
PHP SOAP Request not right
I am trying to consume a web service with no success. It looks like the xml is no properly set.
This is my PHP code:
<?php
$wsdlUrl = "http://api.clickatell.com/soap/webservice.php?WSDL";
$serviceUrl = "http://api.clickatell.com/soap/webservice.php";
$request = array("user"=>"anyuser",
"password"=>"asdsda",
"api_id"=>"1234"
);
var_dump($request);
try {
$client = new SoapClient($wsdlUrl, array("trace" => 1, "location" => $serviceUrl));
var_dump($client);
echo "\n";
$response = $client->auth($request);
var_dump($response);
var_dump($client->__getLastRequest());
echo "\n";
}
catch(Exception $exp) {
echo "EXCEPTION";
}
?>
And the SOAP packet is:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.clickatell.com/soap/webservice" 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-ENV:Body>
<ns1:auth>
<api_id xsi:type="xsd:int">1</api_id>
<user xsi:nil="true"/>
<password xsi:nil="true"/>
</ns1:auth>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What is wrong with the code that causes that api_id, user and password are not being sent?
If you check out var_dump($client->__getFunctions()), you can see, that the parameters have to be passed like with a normal function call.
So you could do either the verbose thing with SoapParam:
$response = $client->auth(
new SoapParam($request["api_id"], "api_id"),
new SoapParam($request["user"], "user"),
new SoapParam($request["password"], "password")
);
Or less verbose by just giving the parameters directly:
$response = $client->auth($request["api_id"],
$request["user"], $request["password"]);
To start off with, I am a beginner at soap.
I am trying to make a soap call to a service and was given a working sample that comes from talend. What I need is to make a similar call in PHP.
The output from talend is as follows, (extracted from the HTTP request)
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<root>
<request>
<username>a#a.com</username>
<password>md5sumlookalike</password>
<webservice>GetCust</webservice>
<refid>12343321</refid>
<message>reserv#123</message>
</request>
</root>
</soap:Body>
</soap:Envelope>
So I wrote a little bit of PHP as it works as a scripting language as well for where it will be called from. Trying to understand how to make a soap call I came up with this bit.
<?php
// Yes I know about the diffrent port issue here. So I wgeted and stored it for use next to script
# $soapClient = new SoapClient("http://123.123.123.123:8088/services", array("trace" => true));
$soapClient = new SoapClient("wsdl", array("trace" => true));
$error = 0;
try {
$info = $soapClient->__soapCall("invoke",
array
(
new SoapParam("a#a.com", "username"),
new SoapParam("md5sumish", "password"),
new SoapParam("GetCust", "webservice"),
new SoapParam("1234321", "refid"),
new SoapParam("reserv#123", "message")
)
);
} catch (SoapFault $fault) {
$error = 1;
echo 'ERROR: '.$fault->faultcode.'-'.$fault->faultstring;
}
if ($error == 0) {
print_r($output_headers);
echo 'maybe it worked\n';
unset($soapClient);
}
?>
I end up seeing the following in the HTTP request via wireshark. The server just does not know what to do with this and does not respond. I am unsure what/where I need to go from here.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://talend.org/esb/service/job">
<SOAP-ENV:Body>
<ns1:invokeInput>a#a.com</ns1:invokeInput>
<password>md5sumish</password>
<webservice>GetCust</webservice>
<refid>1234321</refid>
<message>reserv#123</message>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So I have to ask is how to get rid of the ns1:invokeInput and make it username. Along with bring the rest of the format into line so the request looks like the output from talend?
Here is a working little script I did in php to call a talend tutorial service exported as soap:
//....
if (sizeof($_POST) > 0) {
$name = $_POST['name'];
$city = $_POST['city'];
$client = new SoapClient("http://192.168.32.205:8080/DirectoryService/services/DirectoryService?wsdl", array( 'trace' => 1));
$result = $client->runJob(array(
'--context_param',
'Name=' . $_POST['name'],
'--context_param',
'City=' . $_POST['city']
));
}
//...
Talend seems to be very "basic" regarding how parameters are given.
With this code it was working fine.