Request from SoapUI
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://xxx.xxx.xxx.com/">
<soapenv:Header/>
<soapenv:Body>
<not:SaasNotificationResponse>
<hostID>UCALL</hostID>
<orderID>1180000335810000000010</orderID>
<custID>1180000335770000000010</custID>
<typeTransaction>SUSPENSION</typeTransaction>
<status>3</status>
<message>SUSPENSION 1180000335770000000010</message>
<notifyAttr>
<name>?</name>
<value>?</value>
</notifyAttr>
</not:SaasNotificationResponse>
</soapenv:Body>
</soapenv:Envelope>
Response From SoapUI:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:SaasNotificationResponseResponse xmlns:ns2="http://xxx.xxxx.xxx.com/">
<return>F</return>
<return>Invalid TypeTransaction</return>
</ns2:SaasNotificationResponseResponse>
</S:Body>
</S:Envelope>
Codding PHP Client;
require_once('lib/nusoap.php');
try {
$client = new SoapClient("http://xxx.xxx.xxx/Notification?WSDL");
$data = array( 'hostID' => 'UCALL',
'orderID' => '1180000335810000000010',
'custID' => '1180000335810000000010',
'typeTransaction' => 'ACTIVATION',
'status' => '3',
'message' => 'Activation complete',
'notifyAttr' => array(
array('name'=>'AccountID','value'=>'110022101010'),
array('name'=>'PackageID','value'=>'1')
)
);
$return=$client->SaasNotificationResponse($data);
//$return=$client->call('SaasNotificationResponse',($data));
print_r($return);
}catch (SoapFault $e){
echo $e;
}
Error Application.
Fatal error: Call to undefined method soapclient::SaasNotificationResponse() in C:\wamp\www\spgdtws\notification.php
I have a problem in php webservice applications. if using soapUI. webservice server can be invoked. but when I use the application on the client. error occurs. please help
It seems that you are calling notification WSDL for Telkom's service.
this code works for me
<?php
function sendNotification($orderID,$custID,$typeTransaction,$status,$message) {
try {
$client = new SoapClient("XXXXXXXXX/Notification?wsdl",array("trace"=>1,"exceptions"=>1));
$data = array( 'hostID' => '',
'orderID' => $orderID,
'custID' => $custID,
'typeTransaction' => $typeTransaction,
'status' => $status,
'message' => $message,
'notifyAttr' => array(
array('name'=>'','value'=>''),
array('name'=>'','value'=>'')
)
);
$return=$client->SaasNotificationResponse($data);
var_dump($return);
}catch (SoapFault $e){
echo $e;
}
}
sendNotification('1180000339980000000010','4720562','TERMINATION','3','TERMINATION success');
?>
You don't need to include nusoap. Use native PHP's SOAP instead. SoapClient class is belong to native PHP.
for reference :
http://php.net/manual/en/class.soapclient.php
Related
I am creating an SOAP client using PHP and having issues with consuming. When I test the request direct XML using soapui it responds fine and works but with PHP using SoapClient class it tells me the same credentials which I use in soapui are incorrect.
Not sure what I am missing here. My code below
Below is my XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pric="http://upshot.co.uk/pricing_request_ws">
<soapenv:Header/>
<soapenv:Body>
<pric:retrieveProductsPricing>
<username>apiuser</username>
<password>pword</password>
<postcode>EC2R 7HP</postcode>
</pric:retrieveProductsPricing>
</soapenv:Body>
</soapenv:Envelope>
Below is my PHP
$wsdl = "http://URL?wsdl";
$client = new SoapClient($wsdl, array('trace'=>1));
try
{
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$params = array(
'User name' => 'apiuser',
'Password' => 'pword',
'Postcode' => 'EC2R 7HP'
);
$response = $client->retrieveProductsPricing($params);
print_r($response);
}
catch(SoapFault $e)
{
print_r($e);
This is my first time configuring a soap client so I'm sure I have potentially made a mistake in this.
Have a look at the first code:
<username>apiuser</username>
<password>pword</password>
<postcode>EC2R 7HP</postcode>
You should use the same keys for the array
$params = array(
'username' => 'apiuser',
'password' => 'pword',
'postcode' => 'EC2R 7HP'
);
Useful examples
After over a half a day of trying and reading tutorials on creating a simple SOAP client, I am no closer to retrieving a request from API I attempting to work with.
WSDL: http://publicapi.ekmpowershop31.com/v1.1/publicapi.asmx?WSDL
I can make the request from SOAP UI with the following simple SOAP request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pub="http://publicapi.ekmpowershop.com/">
<soapenv:Header/>
<soapenv:Body>
<pub:GetOrders>
<!--Optional:-->
<pub:GetOrdersRequest>
<!--Optional:-->
<pub:APIKey>myApiKey</pub:APIKey>
</pub:GetOrdersRequest>
</pub:GetOrders>
</soapenv:Body>
</soapenv:Envelope>
This above returns the expected data.
When it comes to translating the request into a PHP I have the following:
$wsdl = 'http://publicapi.ekmpowershop31.com/v1.1/publicapi.asmx?WSDL';
$trace = true;
$exceptions = false;
$debug = true;
$client = new SoapClient($wsdl,
array(
'trace' => $trace,
'exceptions' => $exceptions,
'debug' => $debug,
));
$param = array('GetOrdersRequest' => array(
'APIKey' => 'myApiKey'
)
);
$resp = $client->GetOrders();
print_r($param);
print_r($client->__getLastRequest());
print_r($client->__getLastResponse());
If put the $param into the GetOrders function then, it breaks and nothing happens.
Even if I use an array in the $client->GetOrders(array('someArry' => $param)) then response and request still always looks the same and looks like the body of the SOAP request is never created:
Request:
?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://publicapi.ekmpowershop.com/"><SOAP-ENV:Body><ns1:GetOrders/></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response:
<?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><GetOrdersResponse xmlns="http://publicapi.ekmpowershop.com/"><GetOrdersResult><Status>Failure</Status><Errors><string>Object reference not set to an instance of an object.</string></Errors><Date>2017-04-03T16:00:42.9457446+01:00</Date><TotalOrders>0</TotalOrders><TotalCost xsi:nil="true" /></GetOrdersResult></GetOrdersResponse></soap:Body></soap:Envelope>
If anyone can shed some light on what I am doing wrong here that would be real big help?
P.S My experience of SOAP in PHP is limited as I am used to SOAP in a java env. Thanks
You need to pass the parameters into the $client->GetOrders() call. Also the WSDL defines some required parameters, so a minimal example is something like:
$wsdl = 'http://publicapi.ekmpowershop31.com/v1.1/publicapi.asmx?WSDL';
$trace = true;
$exceptions = false;
$debug = true;
$client = new SoapClient($wsdl,
array(
'trace' => $trace,
'exceptions' => $exceptions,
'debug' => $debug,
));
$param = array(
'GetOrdersRequest' => array(
'APIKey' => 'dummy-key',
'CustomerID' => 1,
'ItemsPerPage' => 1,
'PageNumber' => 1,
)
);
$resp = $client->GetOrders($param);
print_r($param);
print_r($client->__getLastRequest());
print_r($client->__getLastResponse());
This gives the error response:
<Errors><string>Invalid character in a Base-64 string.</string></Errors>
which presumably is because my API key is invalid.
I'm working to connect via web services to another company using PHP. The connection is successful based on the response from the web service. There is not user validation or password in the process.
The validation of the method is successful too based on the result of print_r($client->__getFunctions()) and print_r($client->__getTypes()) where I can see the information on both cases.
The problems come when the parameters are passing to the method, the request don't have the parameters in the XML body :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:GetToken/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I did different kinds of call with the same result:
$response = $client->__soapCall('GetToken', array('parameters' => $params));
or
$response = $client->GetToken(array('parameters' => $params));
or
$response = $client->__soapCall('GetToken', array($params));
or
$response = $client->GetToken(array($params));
Every try is the same response from the web service because the method is not attaching the parameters to the request
[GetTokenResult] => stdClass Object
(
[Token] =>
[Url] =>
[StatusCode] => 400
[StatusDescription] => Value cannot be null.
)
This is my code:
Try{
$wsdlLocation = 'http://webservice.com/Agent.svc?wsdl';
$client = new SoapClient($wsdlLocation,array('location' => $wsdlLocation,
'trace' => true,
'exceptions' => true
)
);
$params = array(
'Key' => '123456',
'ReturnUrl' => 'http://Anyweb.com',
'Name' => 'John Doe',
'Office' => 'NorhWest',
'Business' => 'PL',
'Email' => 'my#email.com',
);
$response = $client->__soapCall('GetToken', array('parameters' => $params));
print_r($response);
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
}
catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
Also, I tested the web service using the XMLspy. Sending a request from this tool with the same values and parameters. The response in this case was successful. So the issue is not the service on the other company.
Any idea how I can resolve this issue. Thanks.
Well, after some time I found the answer of this. The soap service was waiting for an array named 'request' instead of 'parameter'. This fix all the issue.
$response = $client->__soapCall('GetToken', array('request' => $params));
I hope this save time to another people.
How I can do below soap request in php,
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v="http://incometaxindiaefiling.gov.in/ditws/TaxCredMismatch/v_1_0">
<soapenv:Header/>
<soapenv:Body>
<v:getTaxCredMismatchRequest>
<LoginInfo>
<userName>XXXXXXXXXX</userName>
<password>XXXXXXXXXX</password>
</LoginInfo>
<UserInput>
<panNo>XXXXXXXXXX</panNo>
<asseessmentyear>XXXX-XX</asseessmentyear>
</UserInput>
</v:getTaxCredMismatchRequest>
</soapenv:Body>
</soapenv:Envelope>
I tried below code,
<?php
$url = "https://incometaxindiaefiling.gov.in/e-FilingWS/ditws/getTaxCredMismatchRequest.wsdl";
try {
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient($url,$options);
$requestParams = array(
'userName' => 'AJAPA5855E',
'password' => 'pass123',
'panNo' => 'AJAPA5855E',
'asseessmentyear' => '2014-15'
);
$response = $client->__soapCall("getTaxCredMisMatch", array($requestParams));
var_dump($response);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
but getting the response as
SOAP-ERROR: Encoding: object has no 'LoginInfo' property
I know, I'm sending the parameter in correct way, may I know how to correct it.
I never used that soap client, but I would expect this:
<?php
$url = "https://incometaxindiaefiling.gov.in/e-FilingWS/ditws/getTaxCredMismatchRequest.wsdl";
try {
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient($url,$options);
$requestParams = array(
'LoginInfo' => array (
'userName' => 'AJAPA5855E',
'password' => 'pass123',
),
'UserInput' => array (
'panNo' => 'AJAPA5855E',
'asseessmentyear' => '2014-15'
)
);
$response = $client->__soapCall("getTaxCredMisMatch", array($requestParams));
var_dump($response);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
However as said above, this is just a wild guess. It certainly would make sense to take a look at the documentation of that extension: http://php.net/manual/en/class.soapclient.php. Such things should be explained in there...
Using the WSDL from https://incometaxindiaefiling.gov.in/e-FilingWS/ditws/getTaxCredMismatchRequest.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
I am using PHP SoapClient in WSDL mode.
This is what the expected SOAP request should look like:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="http://xml.m4u.com.au/2009">
<soapenv:Header/>
<soapenv:Body>
<ns:sendMessages>
<ns:authentication>
<ns:userId>Username</ns:userId>
<ns:password>Password</ns:password>
</ns:authentication>
<ns:requestBody>
<ns:messages>
<ns:message>
<ns:recipients>
<ns:recipient>61400000001</ns:recipient>
</ns:recipients>
<ns:content>Message Content</ns:content>
</ns:message>
</ns:messages>
</ns:requestBody>
</ns:sendMessages>
</soapenv:Body>
</soapenv:Envelope>
And this is what PHP SoapClient is sending:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://xml.m4u.com.au/2009">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns1:sendMessages>
<ns1:authentication>
<userId>Username</userId>
<password>Password</password>
</ns1:authentication>
<ns1:requestBody>
<messages>
<message>
<recipients>
<recipient>61400000001</recipient>
</recipients>
<content>Message Content</content>
</message>
</messages>
</ns1:requestBody>
</ns1:sendMessages>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is how I constructed the client and params:
function sendMessages($recipient, $content) {
$authenticationType = new SoapVar(array('userId' => $this->username, 'password' => $this->password), SOAP_ENC_OBJECT);
$recipientsType = new SoapVar(array('recipient' => $recipient), SOAP_ENC_OBJECT);
$messageType = new SoapVar(array('recipients' => $recipientsType, 'content' => $content), SOAP_ENC_OBJECT);
$messagesType = new SoapVar(array('message' => $messageType), SOAP_ENC_OBJECT);
$requestBodyType = new SoapVar(array('messages' => $messagesType), SOAP_ENC_OBJECT);
$params = array(
'authentication' => $authenticationType,
'requestBody' => $requestBodyType
);
try {
$this->soapClient = new SoapClient($this->wsdl, array('trace' => 1));
$this->soapClient->__setSoapHeaders(array());
return $this->soapClient->sendMessages($params);
} catch (SoapFault $fault) {
echo '<h2>Request</h2><pre>' . htmlspecialchars($this->soapClient->__getLastRequest(), ENT_QUOTES) . '</pre>';
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
}
Why is 'ns1' present for 'authentication' and 'requestBody' but missing for their child nodes?
What am I doing wrong? The WSDL is located here => http://soap.m4u.com.au/?wsdl
Appreciate anyone who can help.
You must specify the URI of the namespace to encode the object. This will include everything necessary (including your missing namespace). The acronym of the namespace name is irrelevant.
This:
$authenticationType = new SoapVar(array('userId' => $this->username, 'password' => $this->password), SOAP_ENC_OBJECT);
should be:
$authenticationType = new SoapVar(array('userId' => $this->username, 'password' => $this->password), SOAP_ENC_OBJECT, "authentication","http://xml.m4u.com.au/2009");
The problem you're seeing with the namespace serialization comes from using soapvar without all the parameters. When it serializes the request prior to sending it assumes the namespace is already included. If, instead, you had created each as a simple array and included them in $params it would include the namespace for the internal parameters correctly. By way of demonstration:
$authenticationType = array('userId' => $this->username, 'password' => $this->password)
try using nusoap library. Below is sample code:
<?php
$wsdl = "http://soap.m4u.com.au/?wsdl";
// generate request veriables
$data = array();
$action = ""; // ws action
$param = ""; //parameters
$options = array(
'location' => 'http://soap.m4u.com.au',
'uri' => ''
);
// eof generate request veriables
//$client = new soap_client($wsdl, $options);// create soap client
$client = new nusoap_client($wsdl, 'wsdl');
$client->setCredentials($api_username, $api_password);// set crendencials
$opt = $client->call($action, $param, '', '', false, true);
print_r($opt);
?>