SOAPClient won't attach parameters on method call - php

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.

Related

Soap PHP WSDL XML formatting

So I am using Soap client in PHP and I'm trying to make a request on some WSDL. I try to have a specific output but it seems a bit far from what I try to do. Maybe I don't do this right. I'm a bit new to WSDL.
Here is the result I want:
<SOAP-ENV:Body>
<loc:sendSms>
<loc:addresses>9000000000</loc:addresses>
<loc:senderName>9000000</loc:senderName>
<loc:message>test SMS</loc:message>
</loc:sendSms>
</SOAP-ENV:Body>
This is what I try to fit my requirement, but it ends with a server error:
$MCIResp = (array) $_soapClient->__soapCall('sendSms',
'sendMessage' => array(
'addresses' => '9000000000',
'senderName' => '9000000',
'message' => 'test SMS '
)
);
And this is the error I get from this request:
"SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no
'sendmessage' property";
EDIT: Made some improvements on that by getting inspiration on some posts
Here is my code now:
$_soapClient = new SoapClient(
null,
array(
'location' => 'http://someIP/parlayxsmsgw/services/SendSmsService?wsdl',
'uri' => 'http://someIP/parlayxsmsgw/services/SendSmsService?wsdl',
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE,
'use' => SOAP_LITERAL,
'style' => SOAP_DOCUMENT,
'stream_context' => stream_context_create(array(
'http' => array(
'header' => 'servicekey: someservicekey'
),
)),
)
);
$params = new \SoapVar("<sendSms><addresses>90000000000</addresses><senderName>90000000</senderName><message>test SMS</message></sendSms>",XSD_ANYXML);
And then I do a
$_soapClient->whatEverNameHereWillBeIgnored($params);
This is now the XML I generate:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<sendSms>
<addresses>989127184955</addresses>
<senderName>98307066</senderName>
<message>test SMS</message>
</sendSms>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But I receive this as a response:
Unexpected subelement sendSms
do the "loc:" are mandatory to solve this ? Because when I add it in the raw xml it says that
Undeclared namespace prefix "loc"
Thanks,
I strongly advise you to use a WSDL to PHP generator such as PackageGenerator, it will ease you the request construction so you won't have to wonder how to construct the request, it will be cristal clear.

PHP XML Soap request

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

PHP Soap And .Net Dataset

I got an issue here. I am trying make a request to a Web Appi: http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL
And I am sending a request to insertPodData();
I am using PHP and SOAP.
I am succesfull at connecting and giving the correct credentials. However I am not able to send a Dataset (cause I do not know the right way), so i get an empty dataset.
Datasets are for .NET lang. So it is kind of tricky with the php.
I tried already to send it as an array, i still get an empty result.
Here are some coding.
PHP:
$dataset = array(
'schema' => array(
'Enter_Branch_Id' => $speedex_branch_id,
'SND_Customer_Id' => $speedex_cust_id,
'SND_Agreement_Id' => $speedex_appi_key,
'RCV_Name' => 'Test',
'RCV_Addre1' => 'Test Adress',
'RCV_Zip_Code' => '54636',
'RCV_City' => 'Thessaloniki',
'RCV_Country' => 'Greece',
'RCV_Tel1' => '*******',
'Voucher_Weight' => '0',
),
'any' => ''
);
try {
$soap = new SoapClient("http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL",array('trace' => true));
$oAuthResult = $soap->insertPodData(
array(
'username' => $speedex_usrn,
'password' => $speedex_psw,
'VoucherTable' => $dataset,
'_tableFlag' => 3
)
);
$resultVoucher = $oAuthResult;
print_r($resultVoucher);
echo '<br>';
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";
die();
}catch(SoapFault $fault) {
die('<h1>Ooooops something is broken. Refresh or contact module creator </h1><br>'.$fault);
}
This is returning this result
RESULT: stdClass Object ( [insertPodDataResult] => 1 [newVoucherTable] => stdClass Object ( [schema] => [any] => ) )
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:insertPodData>
<ns1:username>****</ns1:username>
<ns1:password>****</ns1:password>
<ns1:VoucherTable>********************TestTest Adress54636ThessalonikiGreece********</ns1:VoucherTable>
<ns1:_tableFlag>3</ns1:_tableFlag>
</ns1:insertPodData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can observe the Dataset is not created and all the values are passed with out a reference.
Any ideas clues? Thanks in advance!

How to debug SOAP connections

Setting up my first SOAP connection. Code below. I can pull down AvailableContent method but cant seem to access any other objects. Is there anything immediately wrong with my code, or is there something I can ask the service provider.
$soapClient = new SoapClient('http://contentcafe2.btol.com/contentcafe/contentcafe.asmx?wsdl', array("trace" => 1, "exception" => 0));
$auth = array(
'userID' => 'XXXXXXX',
'password' => 'XXXXXXX',
'key' => '9781608198214',
'content' => 'AvailableContent'
);
try{
$response = $soapClient->Single($auth);
echo "<pre>";
print_r($response);
echo "</pre>";
}catch (Exception $e) {
}
I think you should use a SOAP client such as SoapUI - http://www.soapui.org/ - to test your soap handshake instead of writing a code to do same.

PHP: Webservice error SoapClient

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

Categories