Solved

Problems using nusoap with document/literal

Posted on 2013-06-26
10
2,606 Views
Last Modified: 2013-11-19
Hi.

I'm facing problems using nusoap from php with document/literal. I tryied with rpc/encoded and works fine, but with document/literal it doesn't work and we need to use document/literal.

The problem is that in document/literal I always gets empty data as result.

This is the php code:

<?php
require_once "nusoap/lib/nusoap.php";

function dades_sanitari($idProfesional, $idCentro){
&#9;// Connexió a la BD
&#9;$cn = mssql_connect('146.219.196.85:1433','sa','rating');
&#9;mssql_select_db('novahis_real',$cn);
&#9;$strSQL = "SELECT numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, CONVERT(varchar,especialitat), up, sexe, convert(varchar,dataNaix,103) FROM pius_sire_prof WHERE codigo_personal = " . $idProfesional;
&#9;$query = mssql_query($strSQL, $cn);
&#9;$numColegiat = mssql_result($query,0,0);
&#9;$tipus = mssql_result($query,0,1);
&#9;$cognom1 = mssql_result($query,0,2);
&#9;$cognom2 = mssql_result($query,0,3);
&#9;$nom = mssql_result($query,0,4);
&#9;$dni = mssql_result($query,0,5);
&#9;$telf = mssql_result($query,0,6);
if (is_null($telf)) $telf = '';
&#9;$especialitat = mssql_result($query,0,7);
&#9;$cup = mssql_result($query,0,8);
&#9;$sexe = mssql_result($query,0,9);
&#9;$dataNaix = mssql_result($query,0,10);
&#9;$a = array(&#9;'nom' => $nom,
&#9;&#9;&#9;&#9;'cognom1' => $cognom1,
&#9;&#9;&#9;&#9;'cognom2' => $cognom2,
&#9;&#9;&#9;&#9;'datanaixement' => (string)$dataNaix,
&#9;&#9;&#9;&#9;'cup' => (string)$cup,
&#9;&#9;&#9;&#9;'dni' => $dni,
&#9;&#9;&#9;&#9;'especialitat' => $especialitat,
&#9;&#9;&#9;&#9;'idprofesional' => (string)$idProfesional,
&#9;&#9;&#9;&#9;'numcolegiat' => (string)$numColegiat,
&#9;&#9;&#9;&#9;'sexe' => $sexe,
&#9;&#9;&#9;&#9;'telefon' => $telf,
&#9;&#9;&#9;&#9;'tipus' => $tipus);
&#9;$retorn = $a;
&#9;return $retorn;
}

$server = new soap_server();

$server->configureWSDL("ws_profesional","urn:ws_profesional",'','document');

//Create a complex type
$server->wsdl->addComplexType('struc_personal','complexType','struct','sequence','',
array( 'nom' => array('name' => 'nom','type' => 'xsd:string'),
'cognom1' => array('name' => 'cognom1','type' => 'xsd:string'),
'cognom2' => array('name' => 'cognom2','type' => 'xsd:string'),
'datanaixement' => array('name' => 'datanaixement','type' => 'xsd:string'),
'cup' => array('name' => 'cup','type' => 'xsd:string'),
'dni' => array('name' => 'dni','type' => 'xsd:string'),
'especialitat' => array('name' => 'especialitat','type' => 'xsd:string'),
'idprofesional' => array('name' => 'idprofesional','type' => 'xsd:string'),
'numcolegiat' => array('name' => 'numcolegiat','type' => 'xsd:string'),
'sexe' => array('name' => 'sexe','type' => 'xsd:string'),
'telefon' => array('name' => 'telefon','type' => 'xsd:string'),
'tipus' => array('name' => 'tipus','type' => 'xsd:string'))); 

$server->register("dades_sanitari",array("idProfesional"=>"xsd:string", "idCentro"=>"xsd:string"),
array("return"=>"tns:struc_personal"),
"urn:ws_profesional",
$server->wsdl->endpoint . "#dades_sanitari",
'document',//"rpc", //"document",
'literal', //"encoded", //"literal",
"WS utilitzat pel modul de receptes electroniques de STACKS per obtenir les dades del professional");

// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($POST_DATA);
?>

Open in new window


This is the request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ws_profesional">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:dades_sanitari>
         <!--You may enter the following 2 items in any order-->
         <idProfesional>802</idProfesional>
         <idCentro>1</idCentro>
      </urn:dades_sanitari>
   </soapenv:Body>
</soapenv:Envelope>

Open in new window


This is the response:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body>
      <dades_sanitariResponse xmlns="urn:ws_profesional"/>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Open in new window


and this is the response if I use rpc/encoded instead of document/literal:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:ws_profesional">
   <SOAP-ENV:Body>
      <ns1:dades_sanitariResponse xmlns:ns1="urn:ws_profesional">
         <return xsi:type="tns:struc_personal">
            <nom xsi:type="xsd:string">Jordi</nom>
            <cognom1 xsi:type="xsd:string">Requena</cognom1>
            <cognom2 xsi:type="xsd:string">Giro</cognom2>
            <datanaixement xsi:type="xsd:string">08/02/1960</datanaixement>
            <cup xsi:type="xsd:string">00826</cup>
            <dni xsi:type="xsd:string">77782448J</dni>
            <especialitat xsi:type="xsd:string">1</especialitat>
            <idprofesional xsi:type="xsd:string">802</idprofesional>
            <numcolegiat xsi:type="xsd:string">43019280</numcolegiat>
            <sexe xsi:type="xsd:string">M</sexe>
            <telefon xsi:type="xsd:string"/>
            <tipus xsi:type="xsd:string">1</tipus>
         </return>
      </ns1:dades_sanitariResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Open in new window

0
Comment
Question by:gplana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 16

Expert Comment

by:Rose Babu
ID: 39286311
Hi gplana,

can you try this below code which is using document/literal style? partially this works. i.e., it is returning the response structure without data.

<?php

require_once ("nusoap/lib/nusoap.php");

$namespace  = 'ws_profesional'; //or any test url
$server = new soap_server ();

$server->configureWSDL ( 'dades_sanitari', $namespace, false, 'document' );

$server->register ( 'dades_sanitari', 
				    array ('idProfesional' => 'xsd:string', 'idCentro' => 'xsd:string' ), //input param 
				    array ('return' => 'tns:struc_personal'), //output param
				    $namespace, 
					$namespace . '#dades_sanitari', 
				    'Document', // style
				    'literal', // use
				    'Document Literal Type WS', // documentation
				    'http://schemas.xmlsoap.org/soap/encoding/' );				    

$server->wsdl->addComplexType ( 'struc_personal', 'complexType', 'struct', 'sequence', '', 
					array ('nom' => array ('name' => 'nom', 'type' => 'xsd:string' ), 
						   'cognom1' => array ('name' => 'cognom1', 'type' => 'xsd:string' ), 
						   'cognom2' => array ('name' => 'cognom2', 'type' => 'xsd:string' ), 
						   'datanaixement' => array ('name' => 'datanaixement', 'type' => 'xsd:string' ), 
						   'cup' => array ('name' => 'cup', 'type' => 'xsd:string' ), 
						   'dni' => array ('name' => 'dni', 'type' => 'xsd:string' ), 
						   'especialitat' => array ('name' => 'especialitat', 'type' => 'xsd:string' ), 
						   'idprofesional' => array ('name' => 'idprofesional', 'type' => 'xsd:string' ), 
						   'numcolegiat' => array ('name' => 'numcolegiat', 'type' => 'xsd:string' ), 
						   'sexe' => array ('name' => 'sexe', 'type' => 'xsd:string' ), 
						   'telefon' => array ('name' => 'telefon', 'type' => 'xsd:string' ), 
						   'tipus' => array ('name' => 'tipus', 'type' => 'xsd:string' ) ) );

//if in safe mode, raw post data not set:
if (! isset ( $HTTP_RAW_POST_DATA )) 
	$HTTP_RAW_POST_DATA = implode ( "\r\n", file ( 'php://input' ) );

$server->service ( $HTTP_RAW_POST_DATA );

function dades_sanitari($idProfesional, $idCentro) {
	// Connexió a la BD
	$cn = mssql_connect ( '146.219.196.85:1433', 'sa', 'rating' );
	mssql_select_db ( 'novahis_real', $cn );
	
	$strSQL = "SELECT numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, especialitat, up, sexe, dataNaix FROM pius_sire_prof WHERE codigo_personal = " . $idProfesional;
	//echo $strSQL;
	$query_result = mssql_query ( $strSQL, $cn );
	
	while ( $rowData = mssql_fetch_array ( $query_result ) ) {
		//$rowData ['CommentBy']

		//numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, especialitat, up, sexe, dataNaix
		$numColegiat = $rowData ['numColegiat'];
		$tipus = $rowData ['tipus'];
		$cognom1 = $rowData ['cognom1'];
		$cognom2 = $rowData ['cognom2'];
		$nom = $rowData ['nom'];
		$dni = $rowData ['dni'];
		$telf = $rowData ['telefon'];
		$especialitat = $rowData ['especialitat'];
		$cup = $rowData ['up'];
		$sexe = $rowData ['sexe'];
		$dataNaix = $rowData ['dataNaix'];
	}
	
	return array ('nom' => $nom, 
				  'cognom1' => $cognom1,
				  'cognom2' => $cognom2,
				  'datanaixement' => ( string ) $dataNaix,
				  'cup' => (string) $cup,
				  'dni' => $dni,
				  'especialitat' => $especialitat,
				  'idprofesional' => (string) $idProfesional,
				  'numcolegiat' => (string) $numColegiat,
				  'sexe' => $sexe,
				  'telefon' => $telf,
				  'tipus' => $tipus);
}
?>

Open in new window

Partial Response

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body>
      <return>
         <nom/>
         <cognom1/>
         <cognom2/>
         <datanaixement/>
         <cup/>
         <dni/>
         <especialitat/>
         <idprofesional/>
         <numcolegiat/>
         <sexe/>
         <telefon/>
         <tipus/>
      </return>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Open in new window

I'm nearing to get the actual response. Have a look and test it in your end. i'll post the updated code if get the actual response.
0
 
LVL 15

Author Comment

by:gplana
ID: 39286324
Dear srosebabu:

Thank you very much for your answer. I tryied and I'm getting some warnings but yes, after the warnings I'm getting the correct structure...

This is the answer I'm getting from SoapUI:

<br />
<b>Warning</b>:  Missing argument 1 for dades_sanitari() in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>40</b><br />
<br />
<b>Warning</b>:  Missing argument 2 for dades_sanitari() in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>40</b><br />
<br />
<b>Warning</b>:  mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: message: Line 1: Incorrect syntax near '='. (severity 15) in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>47</b><br />
<br />
<b>Warning</b>:  mssql_query() [<a href='function.mssql-query'>function.mssql-query</a>]: Query failed in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>47</b><br />
<br />
<b>Warning</b>:  mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>49</b><br />
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><return><nom/><cognom1/><cognom2/><datanaixement></datanaixement><cup></cup><dni/><especialitat/><idprofesional></idprofesional><numcolegiat></numcolegiat><sexe/><telefon/><tipus/></return></SOAP-ENV:Body></SOAP-ENV:Envelope>

Open in new window

0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 39286463
Hi gplana,

Do you use any of the class object? if so check the values to be passed while initiating an object.

and try to put the below code at the top of your php code to get rid of the warnings

@ini_set('display_errors', 0)

also update the select query as below. where condition's codigo_personal  value surrounded by single quotes.

$strSQL = "SELECT numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, especialitat, up, sexe, dataNaix FROM pius_sire_prof WHERE codigo_personal = '" . $idProfesional . "' ";

and test the code once for the warnings.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Rose Babu
ID: 39286466
Hi gplana,

the problem will be in the fetching SQL data. just update your dades_sanitari functionwith the below one and test it once. the response is returning with data.

function dades_sanitari($idProfesional, $idCentro) {
	// Connexió a la BD
	$cn = mssql_connect ( '146.219.196.85:1433', 'sa', 'rating' );
	mssql_select_db ( 'novahis_real', $cn );
		
	$strSQL = "SELECT numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, especialitat, up, sexe, dataNaix FROM pius_sire_prof WHERE codigo_personal = '" . $idProfesional . "' ";
	//echo $strSQL;
	$query_result = mssql_query ( $strSQL, $cn );
	
//	while ( $rowData = mssql_fetch_array ( $query_result ) ) {
//		//$rowData ['CommentBy']
//
//		//numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, especialitat, up, sexe, dataNaix
//		$numColegiat = $rowData ['numColegiat'];
//		$tipus = $rowData ['tipus'];
//		$cognom1 = $rowData ['cognom1'];
//		$cognom2 = $rowData ['cognom2'];
//		$nom = $rowData ['nom'];
//		$dni = $rowData ['dni'];
//		$telf = $rowData ['telefon'];
//		$especialitat = $rowData ['especialitat'];
//		$cup = $rowData ['up'];
//		$sexe = $rowData ['sexe'];
//		$dataNaix = $rowData ['dataNaix'];
//	}

		$numColegiat = "numColegiat_data";
		$tipus = "tipus_data";
		$cognom1 = "cognom1_data";
		$cognom2 = "cognom2_data";
		$nom = "nom_data";
		$dni = "dni_data";
		$telf = "telefon_data";
		$especialitat = "especialitat_data";
		$cup = "up_data";
		$sexe = "sexe_data";
		$dataNaix = "dataNaix_data";
	
	return array ('nom' => $nom, 
				  'cognom1' => $cognom1,
				  'cognom2' => $cognom2,
				  'datanaixement' => ( string ) $dataNaix,
				  'cup' => (string) $cup,
				  'dni' => $dni,
				  'especialitat' => $especialitat,
				  'idprofesional' => (string) $idProfesional,
				  'numcolegiat' => (string) $numColegiat,
				  'sexe' => $sexe,
				  'telefon' => $telf,
				  'tipus' => $tipus);
}

Open in new window


major problem is the values $idProfesional and $idCentro are not passed to the function. thus the sql statement returned empty data. so only the empty data response returned. since the input param is given correctly, the values are not passed into the function
0
 
LVL 15

Author Comment

by:gplana
ID: 39286510
Thank you again.

I tryied your code and you are right. However, I think the problem now is that the method didn't get the parameters. In fact, this is exactly what it is said by warnings: we can ignore warnings as you told me, but I need the parameters to made the query work.

I put an "echo $strSQL;" statement to see what is the SQL command and the parameter is empty. I also unhide warnings because I think it give some clues to us, but I really don't understand why arguments are missing.

This is the code returned by SoapUI now:

<br />
<b>Warning</b>:  Missing argument 1 for dades_sanitari() in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>40</b><br />
<br />
<b>Warning</b>:  Missing argument 2 for dades_sanitari() in <b>/srv/www/htdocs/ws_professionals/ws_prof2.php</b> on line <b>40</b><br />
SELECT numColegiat, tipus, cognom1, cognom2, nom, dni, telefon, especialitat, up, sexe, dataNaix FROM pius_sire_prof WHERE codigo_personal = '' 
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><return><nom>nom_data</nom><cognom1>cognom1_data</cognom1><cognom2>cognom2_data</cognom2><datanaixement>dataNaix_data</datanaixement><cup>up_data</cup><dni>dni_data</dni><especialitat>especialitat_data</especialitat><idprofesional></idprofesional><numcolegiat>numColegiat_data</numcolegiat><sexe>sexe_data</sexe><telefon>telefon_data</telefon><tipus>tipus_data</tipus></return></SOAP-ENV:Body></SOAP-ENV:Envelope>

Open in new window

0
 
LVL 15

Author Comment

by:gplana
ID: 39293647
Can anyone help me?
0
 
LVL 15

Accepted Solution

by:
gplana earned 0 total points
ID: 39295487
I have found the answer for my own. Seems that NuSoap have some problems with ComplexTypes. I have changed code to return an array and avoid complex types, just as on this example: http://mleiv.com/php-nusoap-documentliteral-web/  and then it works.
0
 
LVL 15

Author Closing Comment

by:gplana
ID: 39305113
I have solved from my own.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

726 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