convert asp soap request to php soap request

jtch07
jtch07 used Ask the Experts™
on
I am new to xml and web services -
I  have an example of a web service request in asp and need to get it into php
I have spent hours trying to understand soap wsdl etc and get this to work with no luck
I would appreciate it if someone would show me what this should look like in php

<%@ Language=VBScript %>
<% OPTION EXPLICIT %>
<%
      dim Account, Username, Password, WebService_URL
      
      Account = "DEMO_415_Standard"
      Username = "DEMO_415_Standard"
      Password = "1234"
      WebService_URL = "http://demo.golfbox.dk/web/services/webservice/news.asmx"

      dim soapMessage, SOAPObject, soapResult

      soapMessage = "<?xml version=""1.0"" encoding=""utf-8""?>" &_
      "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
      "<soap:Header>" &_
            "<UserCredentials xmlns=""http://golfbox.net/web/services/webservice"">" &_
            "<Account>" & Account & "</Account>" &_
            "<Username>" & Username & "</Username>" &_
            "<Password>" & Password & "</Password>" &_
            "</UserCredentials>" &_
      "</soap:Header>" &_
      "<soap:Body>" &_
            "<GetList xmlns=""http://golfbox.net/web/services/webservice/news"">" &_
            "<HeadersOnly>false</HeadersOnly>" &_
            "</GetList>" &_
      "</soap:Body>" &_
      "</soap:Envelope>"

      set SOAPObject = server.CreateObject("MSXML2.ServerXMLHTTP")
      call SOAPObject.Open("POST", WebService_URL, false)

      call SOAPObject.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
      call SOAPObject.setRequestHeader("Content-Length", len(soapMessage))
      call SOAPObject.setRequestHeader("SOAPAction", "http://golfbox.net/web/services/webservice/GetList")

      call SOAPObject.send(soapMessage)

      if SOAPObject.ReadyState = 4 then

            set soapResult = server.CreateObject("msxml2.domdocument.4.0")
            call soapResult.loadXML(SOAPObject.responseText)
            dim nodes : set nodes = SOAPResult.selectNodes("//NewsItem")
            
            dim g
            for g = 0 to nodes.length - 1
                  if nodes(g).selectSingleNode("GUID").text = request.QueryString("News_GUID") then
                        response.Write("<b>&raquo;&nbsp;<a href=""ws_getnews.asp?News_GUID=" & server.URLEncode(nodes(g).selectSingleNode("GUID").text) & """>" & nodes(g).selectSingleNode("Subject").text & "</a></b><br>")
                        response.Write("<div style=""padding-left:15px"">" & nodes(g).selectSingleNode("Body").text & "</div><br/>")
                  else
                        response.Write("&raquo;&nbsp;<a href=""ws_getnews.asp?News_GUID=" & server.URLEncode(nodes(g).selectSingleNode("GUID").text) & """>" & nodes(g).selectSingleNode("Subject").text & "</a><br>")
                  end if
            next
      
      end if
%>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It is easy to do with nusoap, did you see this link  ? http://www.scottnichol.com/nusoapprogwsdl.htm

Author

Commented:
I'm not familiar with xml, web services and soap/nusoap at all.

So i hope somebody will help me all the way, and i will be very greatful
Senior Team Manager
Commented:
Hi,

Try this PHP code. it returns the response. Download the nusoap package and use.

<?php
/*
 * NuSOAP
 *
 * Download the nusoap package from the below url
 * http://sourceforge.net/projects/nusoap/
 * 
 * */
require_once ('nusoap-0.9.5/lib/nusoap.php');

$WSDL_URL = 'http://demo.golfbox.dk/web/services/webservice/news.asmx?wsdl';

$client = new nusoap_client ( $WSDL_URL, 'wsdl', '', '', '', '' );

$err = $client->getError ();
if ($err) {
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}

$msg = "<?xml version='1.0' encoding='utf-8'?>";
$msg .= "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> ";
$msg .= "  <soap:Header> ";
$msg .= "    <UserCredentials xmlns='http://golfbox.net/web/services/webservice'> ";
$msg .= "      <Account>DEMO_415_Standard</Account> ";
$msg .= "      <Username>DEMO_415_Standard</Username> ";
$msg .= "      <Password>1234</Password> ";
$msg .= "    </UserCredentials> ";
$msg .= "  </soap:Header> ";
$msg .= "  <soap:Body> ";
$msg .= "    <GetList xmlns='http://golfbox.net/web/services/webservice/news'> ";
$msg .= "      <HeadersOnly>false</HeadersOnly> ";
$msg .= "    </GetList> ";
$msg .= "  </soap:Body> ";
$msg .= "</soap:Envelope> ";

$soapAction = "http://golfbox.net/web/services/webservice/GetList";

// Call WS using NuSOAP
$result = $client->send( $msg, $soapAction, '', '');

if ($client->fault) {
	echo '<h2>Fault</h2><pre>';
	print_r ( $result );
	echo '</pre>';
} else {
	// Check for errors
	$err = $client->getError ();
	if ($err) {
		// Display the error
		echo '<h2>Error</h2><pre>' . $err . '</pre>';
	} else {
		// Display the result		
		echo '<h2>Response</h2><pre>';
		
		print_r ( $result );
		
		echo '</pre>';
	
	}
}
?>

Open in new window

hope this works for you.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Author

Commented:
Hi

Thank you very much for the effort but i get this error

Error
HTTP Error: socket read of headers timed out

se also here
http://sebberklostergolfklub.dk/php/ws_getnews.php
Rose BabuSenior Team Manager

Commented:
There may be a default timeout set to 0.

so try to place the below code in the top of your php file

ini_set('default_socket_timeout', 160);

OR pass the timeout parameter to the soap client

$client = new nusoap_client ( $WSDL_URL, 'wsdl', '', '', '', '', '60', '60', '');

Try any one of these. Hope this will work....

Author

Commented:
Thank you once again, but i tried all combinations, with no sucess

So i stilll get the same error.

I hope you have yet another solution.

If you have the possibility, you can also test it on your own server to see if it works.
Rose BabuSenior Team Manager

Commented:
Since i didn't use the timeout and i used the code given in comment ID: 38008736, i'm getting the response as below

Response

Array
(
    [GetListResult] => Array
        (
            [News] => Array
                (
                    [NewsItem] => Array
                        (
                            [0] => Array
                                (
                                    [GUID] => d51f7765-ce24-46a3-a028-0782e6ca56d2
                                    [Subject] => Test af soap 2
                                    [Body] => Tester Soap
                                    [PublishDate] => 24-05-2012 00:00:00
                                    [ExpireDate] => 23-08-2012 00:00:00
                                    [Author] => Array
                                        (
                                            [!Firstname] => Admin
                                            [!Lastname] => Adminsen
                                            [!Email] => 
                                        )

                                )

                            [1] => Array
                                (
                                    [GUID] => ffefeff5-ae11-4b52-89ca-5b3b12e40494
                                    [Subject] => Hej test af soap
                                    [Body] => Test af nyhed
                                    [PublishDate] => 11-03-2010 00:00:00
                                    [ExpireDate] => 11-03-2013 00:00:00
                                    [Author] => Array
                                        (
                                            [!Firstname] => Admin
                                            [!Lastname] => Adminsen
                                            [!Email] => 
                                        )

                                )

                        )

                )

        )

)

Open in new window

Let me check the issue you are getting....
Rose BabuSenior Team Manager

Commented:
can you show me your php code?

Author

Commented:
The result you get is perfect.
I just cant repreduce it here.

My code is the following

<?php
/*
 * NuSOAP
 *
 * Download the nusoap package from the below url
 * http://sourceforge.net/projects/nusoap/
 * 
 * */
//include $_SERVER['DOCUMENT_ROOT'].'/php/nusoap-0.9.5/lib/nusoap.php'; 

require_once ('nusoap-0.9.5/lib/nusoap.php');

ini_set('default_socket_timeout', 160);

$WSDL_URL = 'http://demo.golfbox.dk/web/services/webservice/news.asmx?wsdl';

//$client = new nusoap_client ( $WSDL_URL, 'wsdl', '', '', '', '' );
$client = new nusoap_client ( $WSDL_URL, 'wsdl', '', '', '', '', '60', '60', '');

$err = $client->getError ();
if ($err) {
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}

$msg = "<?xml version='1.0' encoding='utf-8'?>";
$msg .= "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> ";
$msg .= "  <soap:Header> ";
$msg .= "    <UserCredentials xmlns='http://golfbox.net/web/services/webservice'> ";
$msg .= "      <Account>DEMO_415_Standard</Account> ";
$msg .= "      <Username>DEMO_415_Standard</Username> ";
$msg .= "      <Password>1234</Password> ";
$msg .= "    </UserCredentials> ";
$msg .= "  </soap:Header> ";
$msg .= "  <soap:Body> ";
$msg .= "    <GetList xmlns='http://golfbox.net/web/services/webservice/news'> ";
$msg .= "      <HeadersOnly>false</HeadersOnly> ";
$msg .= "    </GetList> ";
$msg .= "  </soap:Body> ";
$msg .= "</soap:Envelope> ";

$soapAction = "http://golfbox.net/web/services/webservice/GetList";

// Call WS using NuSOAP
$result = $client->send( $msg, $soapAction, '', '');

if ($client->fault) {
	echo '<h2>Fault</h2><pre>';
	print_r ( $result );
	echo '</pre>';
} else {
	// Check for errors
	$err = $client->getError ();
	if ($err) {
		// Display the error
		echo '<h2>Error</h2><pre>' . $err . '</pre>';
	} else {
		// Display the result		
		echo '<h2>Response</h2><pre>';
		
		print_r ( $result );
		
		echo '</pre>';
	
	}
}
?>

Open in new window

Author

Commented:
you can see the setup of my server here

http://sebberklostergolfklub.dk/info.php
Rose BabuSenior Team Manager

Commented:
My PHP version is 5.3.8. if possible try to test in that version too.

and i have another kind of soap call. it is a PHP soap client function. have this code in a separate php file and test once. i got 'SOAP-ERROR: Encoding: object has no 'HeadersOnly' property...' error. Anyway you try this in your end and let me know.

<?php

	$SoapClientURL = 'http://demo.golfbox.dk/web/services/webservice/news.asmx?wsdl';
	
	//Webservice URL
	$client = new SoapClient($SoapClientURL);
	
	// Add parameters to be added in request
		
	$arrParameters = Array
	(
	    'soap:Envelope' => Array
	        (
	            'soap:Header' => Array
	                (
	                    'UserCredentials' => Array
	                        (
	                            'Account' => 'DEMO_415_Standard',
	                            'Username' => 'DEMO_415_Standard',
	                            'Password' => '1234'
	                        ),
	                    'UserCredentials_attr' => Array
	                        (
	                            'xmlns' => 'http://golfbox.net/web/services/webservice'
	                        )
	                ),
	            'soap:Body' => Array
	                (
	                    'GetList' => Array
	                        (
	                            'HeadersOnly' => false
	                        ),
	                    'GetList_attr' => Array
	                        (
	                            'xmlns' => 'http://golfbox.net/web/services/webservice/news'
	                        )
	                )
	        ),
	    'soap:Envelope_attr' => Array
	        (
	            'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
	            'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
	            'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
	        )
	);

	
	// Call GetList method 
	$response = $client->GetList($arrParameters);

	// Read response
	$GetListResponse = $response -> GetListResult;

	print_r($response);
	
?>

Open in new window

Author

Commented:
The solution above gives me no output at all
http://www.sebberklostergolfklub.dk/php/ws_getnews2.php

I cant update the php version myself, but are you sure that can be the problem?
Rose BabuSenior Team Manager

Commented:
may be the problem will be the PHP version and may not. because the only difference is the php version of mine  with yours.

Ughh..

can you try the code in my comment (comment ID 38008736) by changing the $WSDL_URL without the ?wsdl query string like below with/without timeouts

$WSDL_URL = 'http://demo.golfbox.dk/web/services/webservice/news.asmx';

just give a try

Author

Commented:
Still the same problem.

I have sent my host a mail to ask for a update of the php version.

I hope they will do so in the beginning of next week.

But once again thank you for all the help
Rose BabuSenior Team Manager

Commented:
Hi,

try the solution in the below link before you upgrade the php version

http://drupal.org/node/278014

if no luck then try my first code after you upgrade the php version
Rose BabuSenior Team Manager

Commented:
any luck?

Author

Commented:
unforfunatly not yet
but my host is working on the problem
So i hope it will soon work out

Author

Commented:
My host is still working on the issue so i hope to get it to work soon.

But thank you for all the help, I'm sure it will work in the end.

Author

Commented:
Thank you veru much for the help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial