I am trying to consume a soap service in php. This is the code I am using
define('APIURL','https://cgorders.com/v2.1/Service.asmx?WSDL');
$client = new SoapClient(APIURL);
$search_query = new StdClass();
$search_query ->CustomerID = CustomerID;
$search_query ->ClientPO = $orderID;
$search_query ->AccessToken = $cgTokem; //AccessToken;
$result = $client->GetOrdersByClientPO($search_query);
//echo "<pre>";print_r($result->GetOrdersByClientPOResult->Orders->OrderID);echo "</pre>";exit;
if(isset($result->GetOrdersByClientPOResult->Orders->OrderID))
{
return($result->GetOrdersByClientPOResult->Orders->OrderID);
}
else
{
return('');
}
I am passing appropriate parameters correctly, did not mention them, for security reasons.
I am getting Call to undefined method soapclient::GetOrdersByClientPO() . Can anybody help?
check available functions by calling $client->::__getFunctions(); and see if GetOrdersByClientPO in the returned list
Soap client was not installed over the server, I was testing. After installation, it worked like a charm.
Thank you.
Related
I have a class which I am using $this with and since upgrading from 5.6 to 7.1 I cannot get to work. I'm confused as to why? Please see code sample below:
class user_BL extends BLL {
public function getCurrentUserFromSession($userid) {
$userrecord = array();
$query = new query();
$query->addCriteria("userid", $userid , "=");
$userrecords = $this->getDataByQueryObj($query, new user_DAL());
if (isset($userrecords[0])){
$userrecord = $userrecords[0];
$lastlogindetails = $this->getLastLoginDetailsAsArray();
$userrecord['logindatetime'] = astlogindetails['logindatetime'];
}
return $userrecord;
}
}
getLastLoginDetailsAsArray is a function on the BLL base class. The IDE interprets this ok and sees that its available to be used.
Anyhelp with this would be really helpful.
Thanks,
Deano
EDIT: the error I'm getting is Fatal error: Uncaught Error: Using $this when not in object context
Forgot to add that it was a long day yesterday. :)
After digging into the error I've found the call was being made like this:
user_BL::getCurrentUserFromSession();
which seems to be the problem. Calling it like this:
$userbl = new user_BL();
$userbl->getCurrentUserFromSession();
Corrects this.
Thanks for everyones help.
I have a working soap service with several methods available. I am wondering if it is possible to get the name of the method that the user contacting the service is requesting; for example:
try{
$soapServer = new Zend_Soap_Server('http://path-to-service/wsdl');
$soapServer->setClass('My\Soap\Server\Class');
$soapServer->handle();
// is something like this available? :
// $callName = $soapServer->getLastRequestedMethod();
// or
// $callName = $soapServer->getMethod();
}catch(SoapFault $e){
echo $e->getMessage();
}
I didn't see anything like this in the docs # zend or php.net, but just thought I would check to see if anyone knows a way to do this; would be useful for logging purposes. Thanks!
Zend_Soap_Server supports a getLastRequest() method. Example usage would be:
$soapServer = new Zend_Soap_Server('http://path-to-service/wsdl');
$soapServer->setClass('My\Soap\Server\Class');
$soapServer->handle();
$lastRequestXML = $soapServer->getlastRequest()`;
I have a website that contains a form that makes various SOAP requests at certain points. One of these requests gets a list of induction times returned and displays them to the user in order for them to pick one.
I am getting results returned fine from the SOAP service but unfortunately it seems to be not showing information correctly and even not displaying returned object keys at all.
I have liased with one of the devs at the SOAP end and he says the service is fine and spitting out the cirrect information. He has provided a screentshot:
Here is my code to pull call the method I need for this information:
public function getInductionTimes($options) {
$client = $this->createSoapRequest();
$inductionTimes = $client->FITinductionlist($options);
//die(print_r($inductionTimes));
return $inductionTimes;
}
private function createSoapRequest() {
$url = 'https://fitspace.m-cloudapps.com:444/FITSPACE/MHservice.asmx?WSDL';
$options["connection_timeout"] = 25;
$options["location"] = $url;
$options['trace'] = 1;
$options['style'] = SOAP_RPC;
$options['use'] = SOAP_ENCODED;
$client = new SoapClient($url, $options);
//die(print_R($client->__getFunctions()));
return $client;
}
As you can see I print_r the code right after I have received it to check what I am getting returned and it is this:
As you can see this IDdtstring field is getting completely ignored.
Does anyone have any ideas as to why this may be happening? Is it something to do with encoding? I can't seem to get anywhere on this issue!
Thanks
I was able to retrieve the fields correctly, including IDdtstring, using your basic code. Perhaps you are not sending the parameters correctly?
function getInductionTimes($options) {
$client = createSoapRequest();
$inductionTimes = $client->FITinductionlist($options);
die(print_r($inductionTimes));
return $inductionTimes;
}
function createSoapRequest() {
$url = 'https://fitspace.m-cloudapps.com:444/FITSPACE/MHservice.asmx?WSDL';
$options["connection_timeout"] = 25;
$options["location"] = $url;
$options['trace'] = 1;
$options['style'] = SOAP_RPC;
$options['use'] = SOAP_ENCODED;
$client = new SoapClient($url, $options);
//die(print_R($client->__getFunctions()));
return $client;
}
getInductionTimes(array("IDDate" => "2013-06-28T13:00:00+01:00", "GYMNAME" => "Bournemouth"));
I managed to solve this issue by adding the line of code into my SOAP options array which I then presume was an issue with my WSDL being cached in PHP:
$options['cache_wsdl'] = WSDL_CACHE_NONE;
I need to execute a web service from a php page
The web service is located in the following url
https://www.agemni.com/AgemniWebservices/service1.asmx
The Web Service uses a SOAP protocol to exchange messages.
The WSDL info can be located at https://www.agemni.com/AgemniWebservices/service1.asmx?WSDL
The function in that service that we need to use is ValidateEntity
//ValidateEntity("username", "password", "companyID", 2, keys, values)
So , how can i execute this web service and get result from my php page
A simple example, hope it helps...
$service1 = new SoapClient('https://www.agemni.com/AgemniWebservices/service1.asmx');
//here you instanciate your object with those properties
$entity = new Entity();
$entity->strUsername = 'José';
$entity->strPassword = '123';
$entity->strCompanyName = 'Somethin';
$entity->0 //because your type is int
$res = $service1->ValidateEntity($entity);//here you send the information to your service's method, if I'm not mistaken, it must be a object
$res->ValidateEntityResult;//this is the return of your service.
As I said, it is really simple but works.
See soap calls help from php.net:
http://www.php.net/manual/en/soapclient.soapcall.php
You need to use PHP's SOAP libraries...
http://www.php.net/manual/en/soapclient.soapcall.php
For https WebServices you need to enable openssl extension. The WS use .net it means that the class use type hinting so you need to create the ValidateEntity class, here's the code:
$ws = new soapclient('https://www.agemni.com/AgemniWebservices/service1.asmx?wsdl');
class ValidateEntity {
public $strUsername,
$strPassword,
$strCompanyName,
$objecttype;
}
$parameters = new ValidateEntity();
$parameters->strUsername = 'username';
$parameters->strPassword = 'password';
$parameters->strCompanyName = 'company';
$parameters->objecttype = 1;
echo '<pre>';
print_r($ws->ValidateEntity($parameters));
echo '</pre>';
Been having major issues trying to solve this issue, I'll be happy to give a +500 bounty to someone who can help me get this work.
Basically, I'm trying to call this web service using Nusoap:
https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=QueryCustomer
This is what I've got so far:
class Eway
{
var $username = 'test#eway.com.au';
var $pw = 'test123';
var $customerId = '87654321';
private function setHeaders($client)
{
$headers = <<<EOT
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
<eWAYCustomerID>$this->customerId</eWAYCustomerID>
<Username>$this->username</Username>
<Password>$this->pw</Password>
</eWAYHeader>
EOT;
$client->setHeaders($headers);
return $client;
}
function getCustomer($ewayId = 9876543211000)
{
$url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
$client = new Nusoap_client($url, true);
$this->setHeaders($client);
$args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);
$result = $client->call('QueryCustomer', $args);
print_r($result);
}
}
When I run this code and do $eway->getCustomer() I get the following error:
Array
(
[faultcode] => soap:Client
[faultstring] => eWayCustomerID, Username and Password needs to be specified in the soap header.
)
What am I doing wrong?
If you could fix my class and give me working code which is able to do the QueryCustomer method using the test customer id and return its info, I'll be glad to give you +500 rep and my eternal gratitude. Obviously it'll be 48 hours before I can start the bounty, but I promise that I will do it.
I could be missing the point, but you never actually assign the returned object to $client:
function getCustomer($ewayId = 9876543211000)
{
$url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
$client = new Nusoap_client($url, true);
$client = $this->setHeaders($client);
$args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);
$result = $client->call('QueryCustomer', $args);
print_r($result);
}
You could also set $client as a class variable if desired or by sending the parameter as a reference.
Looking at the data, I do not know if this matters, but you are using var for your class variable declarations and then using private for the function. If you are using php5 I would stay away from the var:
private $username = 'test#eway.com.au';
private $pw = 'test123';
private $customerId = '87654321';
Use the private or public or protected (whichever your class requires) instead to keep consistency. I doubt this will solve your problem, just something to be conscious about.
Possible Solution
Ok, doing some digging of my own, figured this out, you need to encase the actual header you add in a SOAP:Header deal. I tested the below and it was working for me, so give it a try:
private function setHeaders($client)
{
$headers = <<<EOT
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Header>
<eWAYHeader xmlns="http://www.eway.com.au/gateway/managedPayment">
<eWAYCustomerID>$this->customerId</eWAYCustomerID>
<Username>$this->username</Username>
<Password>$this->pw</Password>
</eWAYHeader>
</SOAP:Header>
EOT;
$client->setHeaders($headers);
return $client;
}
It did not return any errors. So yea, it seems that is the likely culprit. (Note I also implemented the $client = $this->setHeaders($client); I mentioned above as well.
And my Final Answer is:
Alright did a bit of digging and found something that works. Not saying it is right, but yea it works.
private function setHeaders($client)
{
$headers = <<<EOT
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
<eWAYCustomerID>$this->customerId</eWAYCustomerID>
<Username>$this->username</Username>
<Password>$this->pw</Password>
</eWAYHeader>
EOT;
$client->setHeaders($headers);
return $client;
}
function getCustomer($ewayId = 123456789012)
{
$url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
$client = new nusoap_client($url);
$client = $this->setHeaders($client);
$args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);
$result = $client->call('QueryCustomer', $args, $namespace='https://www.eway.com.au/gateway/managedpayment', $soapAction='https://www.eway.com.au/gateway/managedpayment/QueryCustomer');
print_r($result);
//echo "\n{$client->request}\n"; // This echos out the response you are sending for debugging.
}
It seems the namespace and soapAction were the key ingredients. I found these using the link you originally posted: https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?op=QueryCustomer
Basically, I just looked at that response, and then did some searching to figure out the soapAction, and then just messed with it until the request being sent matched the page you posted. It returns a failed login, but yea. That generally means something is working, and is probably due to the test data. But that gives you a baseline to go off of.
And the $client->request is a handy debugging tool for the future.
Update 5:
nusoap actually wraps the request with SOAP-ENV, like:
<SOAP-ENV:Header><eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
<eWayCustomerID>87654321</eWayCustomerID>
<Username>test#eway.com.au</Username>
<Password>test123</Password>
</eWAYHeader></SOAP-ENV:Header>
While in the docs for EWay soap:Header must be used. I couldn't find a mention of the latter in nusoap headers.
Update 4:
This link has a good tip:
Got it. It was a case issue but not
there, and their PDF is incorrect.
For anyone that gets this in the
future, the PDF says:
<eWAYHeader
xmlns="http://www.eway.com.au/gateway/managedPayment">
It should be:
<eWAYHeader
xmlns="https://www.eway.com.au/gateway/managedpayment">
So this right here:
$client->setHeaders($headers);
The SoapClient class doesn't have that method. Instead, you can create a new SoapHeader.
private function setHeaders($client)
{
$headers = new stdClass;
$headers->eWAYCustomerID = $this->customerId;
$headers->Username = $this->username;
$headers->Password = $this->pw;
$ewayHeader = new SoapHeader(
"http://www.eway.com.au/gateway/managedPayment",
"eWAYHeader",
$headers
);
$client->__setSoapHeaders(array($ewayHeader));
return $client;
}
Edit: Alright, digging deeper:
private function prepHeaders()
{
return array(
'eWAYHeader' => array(
'eWAYCustomerID' => $this->customerId,
'Username' => $this->username,
'Password' => $this->pw
)
);
}
function getCustomer($ewayId = 9876543211000)
{
$url = 'https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx?WSDL';
$client = new nusoap_client($url);
$args['QueryCustomer'] = array('managedCustomerID'=>$ewayId);
$result = $client->call('QueryCustomer', $args, null, null, $this->prepHeaders());
print_r($result);
}
What happens if you do that?
I know this is not a full solution to the issue, but although this question is quite old, my findings may help lead to a concrete resolution.
I've been experiencing a similar error in relation to your mention of the HTTP "SOAPAction" header. (I am, however, dealing with a different eWay API than you. I'm dealing with the "Rapid API", which last week was renamed to from "Merchant Hosted Payments", which was part of the reason why my script wasn't working).
To return to the point, I found that if you don't specify the HTTP "SOAPAction" header, eWay returns a SoapFault with the following error message.
"System.Web.Services.Protocols.SoapException: Unable to handle request without a valid action parameter. Please supply a valid soap action."
If you add the HTTP "SOAPAction" header, you get an error no matter what you set it to.
"System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: XXX"
I'm also told by a member of eWay's support staff that they have an issues with an internal redirect, which they are now looking into resolving.
<ME> (2012-05-25 02:50:18)
I had an idea of what it could be. What is the "SOAPAction" HTTP header supposed to be set to?
<ME> (2012-05-25 02:52:05)
I couldn't find it in the documentation.
<EWAY_SUPPORT_STAFF> (2012-05-25 02:53:38)
The only thing that is required typically is the endpoint which is https://au.ewaypayments.com/hotpotato/soap.asmx and the <CreateAccessCode xmlns="https://au.ewaypayments.com/hotpotato/">
<EWAY_SUPPORT_STAFF> (2012-05-25 02:54:10)
In my tests it is working but what is happening is that requests are being redirected to the old URL which does not accept the CreateAccessCode method
<ME> (2012-05-25 02:56:58)
You did say that.
<ME> (2012-05-25 02:57:13)
So is this bug happening in the production environment?
<EWAY_SUPPORT_STAFF> (2012-05-25 02:57:57)
Yes it appears so. I have escalated this to Development and attached our last chat transcript and my own test results. They are looking at it now.