Solved

How to use Php with Soap and WSDL to connect with a servers https wsdl connection

Posted on 2011-02-28
3
1,560 Views
Last Modified: 2012-05-11
Hi,
I am trying to connect to an external organizations server with our soap client in php using soap. Our php soap client was working fine in the servers qa environment but is not working in production. Tried using the local_cert option but still the error mentions  Couldn't load from 'https://xyz.com/CondBasedMaintWS/SampleResultSendWSService?WSDL' : failed to load external entity "https://xyz.com/CondBasedMaintWS/SampleResultSendWSService?WSDL

We did the entire testing in qa environment and now when the code has been moved to production by the external organization, we are unable to connect to their wsdl. Also, I am not sure how to retrieve their certificate .The link that they  gave for the certificate i tried to acquire through

openssl s_client -connect https://xyz.com/monitor.html> scert.pem

and it gave me the following error


getaddrinfo: Servname not supported for ai_socktype
connect:errno=0


We can also use Zend if some body can point to a specific Zend framework example. Thank you.
0
Comment
Question by:ezdrt
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 500 total points
ID: 35005545
Can you try this simple test on your servers?

<?php
error_reporting(-1);
ini_set('display_errors', 1);
echo file_get_contents('https://mail.google.com/mail');
?>

Most likely the server without the https capability is missing the necessary elements. Commonly cURL, but openssl too.

On both servers, run ...

<?php
phpinfo();
?>

and compare the output. Pay special attention to any entries with https in them...

The following is from the command line (on Windows so, the find command is different) ...

[2011/03/01  9:46:48] [D:\Personal Files\Downloads\Software\Programming\PHP\Official Releases\PHP5.x.x\PHP5.3.x\php-5.3.5] [] >php -n -i | find "http"
Registered PHP Streams => php, file, glob, data, http, ftp, zip, compress.zlib, phar
session.cookie_httponly => Off => Off

[2011/03/01  9:46:58] [D:\Personal Files\Downloads\Software\Programming\PHP\Official Releases\PHP5.x.x\PHP5.3.x\php-5.3.5] [] >php -n -i -dextension_dir=.\ext -dextension=php_curl.dll | find "http"
Registered PHP Streams => php, file, glob, data, http, ftp, zip, compress.zlib, phar
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
session.cookie_httponly => Off => Off


The first set is without loading any additional extensions and relying purely on the built-in extensions.

As you can see, no https at all.

Once you load cURL, the https protocol is ready to use.

In my experience, once this is set, you are ready to go.

As for using the service, you normally don't need to use anything else other than PHP's built in SOAPClient.

I use a wsdl2php converter which takes the wsdl file and creates a set of classes covering the complex types used in the WSDL as well as a sub class of SOAPClient allowing for very easy usage of the soap service.

The protocol handling is all done by SOAPClient.

If you can provide a real URL for the wsdl file, I can give you back the proof of concept work that I use.

You can see other examples of my working in the PHP SOAP mailing list, http://news.php.net/php.soap.

Pretty much all the posts I've made here are in response to the question of "How do I use PHP to talk to a web service using a wsdl file?".

For https, you need curl to be loaded. That way curl handles all the ssl aspects and allows the SOAPClient class to simple talk in SOAP terms. The code created by wsdl2php allows you to talk in object terms. You don't need to worry about XML, SOAP, HTTPS.

Well. Mostly.

The only time you have to think about XML is when the service doesn't provide a complex type to handle the response. Some services response types are strings containing XML. I use the Tidy extension to show them, but using the simplexml extension to convert the XML string to an object keeps everything in the object domain. For me that's a level of consistency I like.

I hope this is of use.

If you need more info, specific to your issue or more general stuff, please come back to me.

Richard.
0
 
LVL 7

Expert Comment

by:Vimal DM
ID: 35006661
Hai,

I have used "nusoap.php" class for the integration of SOAP with PHP

Steps:

1) Variables to be sent
2) require_once('nusoap.php');
3) $client = new nusoap_client(include the xml file,true)
4) $err = $client->getError();
5) $result = $client->call('WS_NAME',VARIABLES,'urn:WEB_SERVICE_SOAP');

Just search related topic and understand the usage of the "nusoap",it sounds good

0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 35007001
Watch out that nusoap is for PHP4.

PHP5 has all that built in and is supported/maintained by The PHP Group.

And please read http://code.google.com/p/nusoap-for-php5/ ...

"NuSOAP for PHP 5 modifies the NuSOAP library so that it doesn't have a class name conflict with the PHP5 soap extension.

NuSOAP's class name is 'soapclient'. PHP5 includes a SOAP extension whose class name is also 'soapclient'. As a result, you effectively can't use NuSOAP with PHP5. NuSOAP for PHP5 simply changes the class name to 'soapclientnusoap'."


Considering PHP natively supports SOAP, there would have to be some compelling reasons to use a nusoap. Using PHP 4 is certainly 1 reason and a perfectly valid one.


Richard.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question