Wednesday, July 16, 2014

PHP SoapClient error: Could not connect to host


It is a mystery why this piece of code caused a SoapFault exception:
 
<?php
 
  $wsdl = "http://myws.toptip.ca/myws.wsdl";

  $client = new SoapClient($wsdl, array(
                   "trace" => 1,
                   "exceptions" => 1));

  $parameters = array("Element1" => "data1", "Element2" => "data2");

  $response = $client->myFunction($parameters);

?>

An important fact was that the soap address location inside the WSDL is using a port other than 80, e.g.

 http://myws.toptip.ca:8080/mywebservice

The exception was captured in /var/log/httpd/error_log:

PHP Fatal error: Uncaught SoapFault exception: [Http] Could not connect to host in ...

I tried to use Wireshark to capture the packets sent and received. Surprisingly, there was no packet sent out to the server from SoapClient. Not even the attempt to connect.

Accidentally, I found out an interesting thing. When I changed the port number of the soap address location in the WSDL file to the default (80), e.g.

http://myws.toptip.ca/mywebservice

SoapClient actually tried to connect to the service.

Why???

Sorry, I don't have the answer. If you have a clue, please let me know.

However, I have a workaround.

I installed the squid proxy on port 80 of the localhost. Then when creating the SoapClient object, I added the "proxy_host" and "proxy_port" options. Bang! It worked!! SoapClient sent the request to the proxy and it was successfully forwarded to the web service location.

Saturday, July 5, 2014

Create a Web Service from a WSDL with Eclipse


  1. Create an empty Dynamic Web Project (New->Project...->Web->Dynamic Web Project).
  2. Important Note: In the "Dynamic Web Project" dialogue, select a version less than 3.0 for the Dynamic web module version, e.g. 2.5. Otherwise, we will get an error of Apache Axis2 Web service runtime in Tomcat v7.0 Server does not support the service project <MyProject> in a later step.
  3. Right click on the project and select New->Others...
  4. In the "Select a wizard" dialogue, select Web Services->Web Service, and click the "Next" button.
  5. Select Top down Java bean Web Service for the Web Service type option. Input the URL of the web service in the Service definition box.
  6. Drag the slider on the left to choose Start service. Click the "Next" button.
  7. Follow the prompts to create the web service and start Tomcat.
  8. The web service skeleton is generated and we can fill in our implementation of the business logic.

Saturday, June 28, 2014

Web Dictionary Widget



 If you like our Wiktionary and Google Translate, you will be interested in its sister project -- our new Web Dictionary Widget. Check it out at dic.solezero.com.
 
Get This <