I have an issue with consuming a web service in PHP - php

I have some problem with consuming web service wsdl php client.
I need to read all information from the service but he return this java.lang.NullPointerException but if I limit at 100 its works. I don't know where is the problem.
This my code
ini_set("soap.wsdl_cache_enabled", "0");
$client = new soapclient("http://localhost:8080/ProjectServices/services/Services?wsdl");
$param = array(__function__ => array('requete' => $sql,'limit' => $limit,'offset' => $Ndeb));
$response = $client->__soapCall("listproduit", $param);
var_dump($response);

Related

Status call back not working in twilio

Iam using twilio Programmable voice while trying to Tracking the call status of an outbound call and save it log whether the user answer or cut the call ,but the problem i didn't get any log and while checking in twilio debugger it showing error:15003
Here my Code:
<?php
require_once "vendor/autoload.php";
use Twilio\Rest\Client;
$AccountSid= 'AC04421826f5ffaa58eaefa1ba6984dac2';
$AuthToken= 'token';
$client = new Client($AccountSid, $AuthToken);
try {
$call = $client->account->calls->create(
// to call.
"+9120000000",
"+1209000001",
array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "GET",
"statusCallbackMethod" => "POST",
"statusCallback" => "localhost/twilio/log.txt",
"statusCallbackEvent" => array(
"initiated", "ringing", "answered", "completed"
)
)
);
echo "Started call: " . $call->sid;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
Twilio evangelist here.
Looks like you have set the statuscallback property to point to localhost.
localhost is a domain that is only reachable from your own local machine so Twilio does not how to reach the localhost running on your local machine.
I'd suggest checking out ngrok which is a simple tool that lets you expose the web server running on your local machine via a publicly addressable domain.
Hope that helps
The issue here is a GET or POST request cannot be written directly to log.txt file and the file should be hosted on a http domain.
change the following code
"statusCallback" => "localhost/twilio/log.txt",
to
"statusCallback" => "http://yourdomain.com/twilio/log.php",
as you rather need an additional file log.php which can write to log.txt
<?php
$status = implode(',',$_REQUEST) ;
$handle = fopen('log.txt','a');
fwrite($handle, $status);
?>

Using soap-client over HTTPS in PHP

i have problem with using soapclient in php. I have this code
$url = 'https://example.com?wsdl';
$soap = new SoapClient($url, array('trace' => true));
print_r($soap->__getFunctions());
$requestHeader = array(..);
$requestObject = array(..);
$request = array(
"Header" => $requestHeader,
"RequestObject" => $requestObject,
);
$createResponse = $soap->ServiceList(array('Request' => $request));
Which returns this error
Uncaught SoapFault exception: [HTTP] HTTP to HTTPS communication - Please reconfigure Your client to use HTTPS secured communication on port 443
Calling __getFuncitons is ok, it prints aviable functions, but when i call some of that functions, i get that error. I was searching for some tutorial or advice, but unsuccessfully. Do you have any advice for me ?

Call https asmx web service from PHP with multiple parameters wordpress blog

I am trying to call a HTTPS ASMX service from my PHP blog
Here is my code
$param1="Web Submission";
$param2="Lead";
$param3="flase";
$param0=$comment_content;
if (!empty($comment_content)){
$client = new SoapClient("https://devop.setars.com/webservice/sellblog.asmx?wsdl");
$params->Notes=$param0;
$params->Type=$param1;
$params->PURPOSE=$param2;
$params->IsMail=$param3;
$result=$client->AddActivity($params);
}
When I tested this locally with HTTP it is working fine, but when hosting with HTTPS, it doesn't appear to be making the call correctly.
$param1="Web Submission";
$param2="Lead";
$param3="flase";
$param0=$comment_content;
if (!empty($param0)){
$client = new SoapClient("http://localhost:52078/WebService/SellBlog.asmx?wsdl");
$params->Notes=$param0;
$params->Type=$param1;
$params->PURPOSE=$param2;
$params->IsMail=$param3;
$result=$client->AddActivity($params);
}
I tried with this also but no solution
$soap_options = array(
'trace' => 1,
'exceptions' => 1 ,
);
$wsdl = "https://dev234.sentsis.com/webservice/sellblog.asmx?WSDL";
$param1="Web Submission";
$param2="Lead";
$param3="flase";
$param0=$comment_content;
if (!empty($comment_content)){
$client = new SoapClient( $wsdl, $soap_options);
$params->Notes=$param0;
$params->Type=$param1;
$params->PURPOSE=$param2;
$params->IsMail=$param3;
$result=$client->AddActivity($params)->AddActivityResult;
}
Is there any difference between making a service call from PHP to a HTTP service compared to a HTTPS one?
If you want to connect to a server that only supports SSLv2/3 and/or TLS 1.0 (no TLS 2 or 3), tell the SOAP client if you get a connection error by setting the appropriate stream context, example:
<?php
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA')
);
$client = new SoapClient(
'https://example.com/?wsdl',
array ( "encoding"=>"ISO-8859-1",
'stream_context' => stream_context_create($opts)
// your options
);
?>
You might need to disable the SOAP caching of WSDLs in order for the SOAP client to use the new context.

Getting fatal-error on Calling WCF in PHP using SoapClient over https

I am newbie to services, i am currently calling .net WCF service in PHP using SoapClient object. Code is as follows:
$arr2=array('paymentVendorCode'=>"test1",'transactionNumber'=>123456789,'dataSource'=>'Ghana_QA','customerNumber'=>45678912,'amount'=>10,'invoicePeriod'=>1,'currency'=>'GHC','paymentDescription'=>'CashPayment','methodofPayment'=>'CASH','productCollection'=>'PRCC4');
$certFile = "certs/Entrust.pem";
$options = array('soap_version' => SOAP_1_1 , 'local_cert' => $certFile , 'exceptions' => true ,'trace' => true ,'wdsl_local_copy' => true ,'ssl' => array('verify_peer' => false) ,'https' => array('curl_verify_ssl_peer' => false, 'curl_verify_ssl_host' => false)
);
try
{
echo "SOAP Client Object Made <br />";
//To Make soap client using WSDL files offline
$client = new SoapClient("RTPP_Web_Service_WSDL_20130306/multichoice.paymentservice.wsdl",$options);
}
catch(SoapFault $E)
{
echo "Error:--> ".$E->faultstring;
}
print_r($client->__getFunctions());
try
{
echo $pmt_customer=$client->__call("SubmitPayment", $arr2)."<br /><br />";
}
catch(SoapFault $fault)
{
echo "came here in catch";
trigger_error("SOAP Fault:(faultcode: {$fault->faultcode}\n"."faultstring: {$fault->faultstring})", E_USER_ERROR);
}
I have go through all WSDL files i am using and got all elements, messages, operations, parameters etc. In one of the WSDL file soap address is as follows:
<soap:address location="https://wispqa.multichoice.co.za/PaymentServicePerimeter/Intermediate.svc" />
which is actual address of service being called, normally services are called with ?WSDL at the end of url but even after adding this at the end of above url the service page appearance remains same.
One thing in service documentation is written as "The service currently does not make use of message contracts."
I am sending request to service calling one of its methods from the list that i got by calling "$client->__getFunction()". But instead of response it is giving fatal error that can be seen from the screenshot at http://i.stack.imgur.com/GvS3d.png.
I have been working on it for a almost a week but got stuck here. Please if anybody can get me out of here. Thanks in advance.
I got my answer, What i was missing is soap action for the method to be called. I have given soap action by visiting WSDL files thoroughly and found soap action for method i was calling as:
$submitpayment_action = "http://MultiChoice.PaymentService/ServiceContracts/PaymentServiceContract/SubmitPayment";
Also i have changed format of my request by using xml format whose excerpt is as follows(i have got this xml format by using SOAPUI tool):
$submitpay = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:mes=\"http://MultiChoice.PaymentService/MessageContracts\"
xmlns:ser=\"http://MultiChoice.PaymentService/ServiceContracts\"
xmlns:dat=\"http://MultiChoice.PaymentService/DataContracts\"
xmlns:mcom=\"http://mcomp.scontracts\" xmlns:mcom1=\"http://mcomp.dcontracts\">
<soapenv:Header/>
<soapenv:Body>
<mes:SubmitPaymentRequest>
<ser:PaymentRequest>
<dat:paymentVendorCode>".$vendorcode."</dat:paymentVendorCode> .......
and finally using this "__doRequest" SOAP method to call service method as:
$response = $client->__doRequest($submitpay,$location,$submitpayment_action,SOAP_1_1,$one_way = 0);
print_r($response);
This show me the desired response. Now one can extract required information from the response using "simplexml_load_string($response);" , "registerXPathNamespace()" and "xpath('//string');" methods.

Can't connect to MS web service via PHP's SoapClient

I'm having some problems connecting to MS web service hosted at appharbor.com
Here's the php code:
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
try {
$client = new SoapClient("http://ppjparsanje.apphb.com/Prazniki.asmx?wsdl", $options);
print_r($client->__call("get_praznike", array("json")));
print_r($client->get_praznike("json"));
print_r($client->__soapCall("get_praznike", array("json"), array('soapaction' => 'http://ppjparsanje.apphb.com/get_praznike')));
} catch(Excteption $e) {
echo $e->getMessage()."<br />";
}
The error is:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host
Which is strange because service seems to work fine. I have also tried to add port 14275, but no luck. Any suggestions?
Thanks in advance!
you have made a mistake the soap has version 1 na your are passing 1.2 in options then how will it connect
$soapClient = new SoapClient('http://ppjparsanje.apphb.com/Prazniki.asmx?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE) );
print_r($soapClient);
i get output:- hence due to bad code you are getting error
SoapClient Object ( [_soap_version] => 1 [sdl] => Resource id #3 )
well here i have acceses uk mail api
take a look at how i have called a method its bit diffrent
but u will get an idea
php soap client for uk mail webservice api?

Categories