Solved

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

Posted on 2011-02-28
3
1,529 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:
RQuadling earned 500 total points
Comment Utility
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
Comment Utility
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:RQuadling
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now