Avatar of jtch07
jtch07
 asked on

convert asp soap request to php soap request

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
%>
PHPWeb Services

Avatar of undefined
Last Comment
jtch07

8/22/2022 - Mon
Loganathan Natarajan

It is easy to do with nusoap, did you see this link  ? http://www.scottnichol.com/nusoapprogwsdl.htm
jtch07

ASKER
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
ASKER CERTIFIED SOLUTION
Rose Babu

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jtch07

ASKER
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Rose Babu

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....
jtch07

ASKER
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 Babu

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....
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Rose Babu

can you show me your php code?
jtch07

ASKER
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

jtch07

ASKER
you can see the setup of my server here

http://sebberklostergolfklub.dk/info.php
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Rose Babu

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

jtch07

ASKER
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 Babu

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
jtch07

ASKER
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 Babu

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 Babu

any luck?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
jtch07

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

ASKER
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.
jtch07

ASKER
Thank you veru much for the help
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.