I am not sure if this is the right place for it, but I am hoping a few of you are familiar with PHP cURL as well as SOAPUI.
I have managed to successfully submit a web services request using SOAPUI, but have had no luck using php. PHP is currently timing out at 30 seconds (I also tried raising the timeout to 3mins). The SOAPUI request takes about 3 seconds to finish.
If any of you could spot where I went wrong, it would be greatly appreciated!
Thanks
Below are my properties for SOAPUI - endpoint is https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc:
SOAPUI Request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:eclg:coursecopy:enterprisecourse" xmlns:v2="http://CCWS-Services.eCollege.com/EnterpriseServices/Types/v2.1/">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Action>urn:eclg:coursecopy:enterprisecourse:createcoursesection:request</wsa:Action>
<wsa:To>http://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc</wsa:To>
</soap:Header>
<soap:Body>
<urn:CreateCourseSection>
<urn:createCourseSection>
***REMOVED****
</urn:createCourseSection>
</urn:CreateCourseSection>
</soap:Body>
</soap:Envelope>
I took the RawRequest from SOAPUI and used it as the XML payload for PHP ($post_string).
Here is my PHP code -I suspect the error comes from the SOAPAction, which I retrieved from SOAPUI's Operation Properties:
define('XML_POST_URL', 'https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc');
$headers = array(
'Content-Type: text/xml; charset=utf-8',
'Content-Length: '.strlen($post_string),
'Accept: text/xml',
'Cache-Control: no-cache',
'Pragma: no-cache',
'SOAPAction: urn:eclg:coursecopy:enterprisecourse:createcoursesection:request'
);
/**
* Initialize handle and set options
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4000);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
/**
* Execute the request and also time the transaction
*/
$result = curl_exec($ch);
You can try this. This is what I used when I wound up using cURL in .php for a SOAP Web-Service.
$envelope = '<soap:Envelope> .... </soap:Envelope>';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://ccws-services.ecollege.com/EnterpriseServices/v2.1/EnterpriseCourse.svc" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $envelope);
curl_setopt($soap_do, CURLOPT_VERBOSE, TRUE);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($envelope)));
$result = curl_exec($soap_do);
I do time out trying to connect to it. Try it on your end and see if it works with your username and password.
Related
I tried try to get Token, but answer always blank. What i doing wrong?
$post_string = '
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:GetToken>
<tem:WebChanelID>8</tem:WebChanelID>
<tem:AccessCode>444555</tem:AccessCode>
</tem:GetToken>
</soap:Body>
</soap:Envelope>
';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "https://hma.ecvi.ru/service/webform.wsdl.php" );
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($post_string) ));
$result = curl_exec($soap_do);
$err = curl_error($soap_do);
I need to get an answer, but it's always blank.
in one of my projects i need to send SOAP request to remote servers. For doing so i am using below script (using CURL). For some reason i am not getting any response if i ran below script.
If i try sending requests via SOAP UI, all works just like it should be. When replicating functionality in php, i get no response at all and not able to identify what the problem is.
public function sendRequestAction ($cntiin) {
$userid = 'XXXXX';
$clientid = 'YYYYY';
$password = 'Test_Test';
$urltest = 'https://y.fake.url/testServices/PersonDetailsImplService';
//variable defenition
$identifier = '700521700054';
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:data="http://data.fake.url.test.net">
<soapenv:Header>
<userId>3d4f80d7</userId>
</soapenv:Header>
<soapenv:Body>
<data:getPerson>
<!--Optional:-->
<iin>' . $identifier . '</iin>
<!--Optional:-->
<consentConfirmed>true</consentConfirmed>
</data:getPerson>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: https://y.fake.url/gbdServices/PersonDetailsImplService",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
// PHP cURL for https connection with auth
$url = $urltest .'?wsdl';
$ch = curl_init();
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, $clientid.":".$password); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($response);
}
When sending requests via SOAP UI there is Basic Auth with login and password, which i believe is accounted for above. Still no results
I went thruogh numerous articles including:
this one and this one and many others but still not sure why not working, so any feedback will be highly appriciated.
I am trying to integrate the SOAP xml request using PHP CURL method I have tried a lot of methods to get a response from the client system but always goes for a failed message. Below is the code which I am trying it,
<?php
$envelope = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:rbss="RBSS"><soap:Header/><soap:Body><rbss:PushData><!--Optional:--><rbss:xml><RBSS><ead_Response_DateTime>20-05-2016 10:25:16 </Lead_Response_DateTime><Lead_Push_DateTime>20-05-2016 10:25:16 </Lead_Push_DateTime><Lead_Recd_DataTime>20-05-2016 10:25:16 </Lead_Recd_DataTime><FirstName>Ismail</FirstName><Phone1>7760120077</Phone1><Phone2>7760120077</Phone2><Email>test#gmail.com</Email><DOB>20-05-2016</DOB><Age>25</Age><Child_DOB>20-05-2002</Child_DOB><Child_Age></Child_Age><Pincode>400052</Pincode><City_Name>Bangalore</City_Name><Address>2, Akshardhamů..</Address><Annual_Income>1000000</Annual_Income><Annual_Income_Slab></Annual_Income_Slab><SMS_Keyword></SMS_Keyword><Short_Code></Short_Code><Circle_Operator></Circle_Operator><Sum_Assured></Sum_Assured><Premium_Pitched></Premium_Pitched><Company_Name>WRS </Company_Name><Website_Name>indiainverstors.in </Website_Name><UTN_Source>FaceBook </UTN_Source><Lead_Source></Lead_Source><Type_Of_Lead></Type_Of_Lead><Verification_Type></Verification_Type><Product_Name></Product_Name><Product_Category></Product_Category><No_of_Companies></No_of_Companies><Names_of_Companied></Names_of_Companied><SMS_Message_Sent></SMS_Message_Sent><Customer__Remarks></Customer__Remarks><FLAG></FLAG><Lead_Type>INCOMING_WEB</Lead_Type><Channel_Type>INTERNET</Channel_Type><Mode_Type>PREFIXED_APPOINTMENT</Mode_Type><Source_Type>Valueleaf</Source_Type><Campaign_Type>APR_16</Campaign_Type><Opportunity_Id>123456</Opportunity_Id><PROSPECT_ID></PROSPECT_ID><Title>MR</Title><UID></UID><LastName>Malik</LastName><Gender>Male</Gender><MaritalStatus></MaritalStatus><MobileNo>7760120077</MobileNo><AgeAtRetirement></AgeAtRetirement><VendorCSE_Name></VendorCSE_Name><TermOfPlan></TermOfPlan><Smoker_NonSmoker></Smoker_NonSmoker><VendorCode></VendorCode><MeetingDate>20-01-2017</MeetingDate><MeetingTime></MeetingTime><City_ID>11</City_ID><ID>123</ID><CallcenterID></CallcenterID><ADDLInfo1></ADDLInfo1><ADDLInfo2></ADDLInfo2></RBSS></rbss:xml></rbss:PushData></soap:Body></soap:Envelope>';
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "http://company.service.com/IPRU_PFA_Vendor_Data/Service.asmx?op=PushData");
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $envelope);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "Content-length: ".strlen($envelope)));
$result = curl_exec($soap_do);
print_r($result);
curl_close($soap_do);
if($result==true)
{
echo "success";
}
else
{
echo "Something went wrong";
}
?>
Everytime the else statement is giving the output. Can anyone say me where exactly I am going wrong.
I would like someone with experience in SOAP requests with Curl and PHP to assist me. I have the situation where I am making SOAP PHP requests from my PHP app to remote server which is working great from my local server (PHP 7.0 , Curl 7.47 )
The problem is when I deploy the app on my server with PHP 5.5.9 and curl 7.50 , with completely same code, I get empty response from the Curl call. Here is the part of the code:
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tcit="urn:microsoft-dynamics-schemas/page/tcitems">';
$xml_post_string .= '<soapenv:Header/>';
$xml_post_string .= '<soapenv:Body>';
$xml_post_string .= '<tcit:ReadMultiple>';
$xml_post_string .= '</tcit:ReadMultiple>';
$xml_post_string .= '</soapenv:Body>';
$xml_post_string .= '</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: `here goes my remote url which I am calling`"
);
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
Actually I get empty string as a response, but when I debugged I saw that problem is 401 request (Something with auth?). Anyway the script is working perfectly from my localhost, so I suppose it is related to some version incopatibility on remote Server. Let me hear your thoughts and what do you think in this configuration can be the problem.
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); (this return 401)
$curl_errno= curl_errno($ch); (this returns 0)
I am trying to call a web service through php . I am sending an XML request for which I am supposed to get back an Xml response. But I as response I am getting only the data without the xml tags. I want it in proper xml format. I also have the wsdl file of the website. If anyone can advise what to do it will be of real help. Thanks in advance for your time.
<?php
$soapUrl=some url';
$xml_post_string='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sec="http://schemas.xmlsoap.org/ws/2002/04/secext" xmlns:urn="urn:ebx-schemas:dataservices_1.0">
<soapenv:Header>
<sec:Security>
<UsernameToken>
<Username>Some Value</Username>
<Password>Some Value</Password>
</UsernameToken>
</sec:Security>
</soapenv:Header>
<soapenv:Body>
<urn:select_ProductDetail>
<branch>Product</branch>
<instance>Product</instance>
<viewPublication>List Name</viewPublication>
</urn:select_ProductDetail>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-Type: text/xml;charset=UTF-8",
"Accept: gzip,deflate",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"select\"",
"Host: Host name",
"Connection: Keep-Alive",
"Content-length: ".strlen($xml_post_string),
);
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $soapUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_MAXREDIRS, 12);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ss = curl_getinfo($ch);
$response = curl_exec($ch);
print_r($response);
exit;
curl_close($ch);
?>
Try modifying your codes to below, for viewing it in BROWSERS
$ss = curl_getinfo($ch);
$response = curl_exec($ch);
echo '<pre>';
echo htmlspecialchars(print_r($response, true));
echo '</pre>';
#print_r($response);
exit;
curl_close($ch);
You are not getting output in xml format because output is getting concatenated with header of curl to avoid so use below code
// PHP cURL for https connection with auth
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $soapUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_MAXREDIRS, 12);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$ss = curl_getinfo($ch);
//$response will give you xml format code
$response = curl_exec($ch);
//$xml will create array from that xml format code
$xml=simplexml_load_string($response);
print_r($xml);
exit;
curl_close($ch);