i am calling a client in a browser, and sending an array of arrays as a parameter to a server function, it return mein first key value pair that fine, but it only send me key of the second array not its value, please help me out.
Client
<?php
require_once("nuSOAP/lib/nusoap.php");
$id = array('ID'=>'1234','type' => 'int');
$MyComplexType = array(
'ID'=> $id,
'YourName' =>array('YourName' => '123','type' => 'string')
);
//Create object that referer a web services
$client = new soapclient('http://localhost/server/server2.php');
//Call a function at server and send parameters too
$response = $client->call('HelloComplexWorld',$MyComplexType);
//Process result
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
echo"<pre>";
print_r($response);
echo "</pre>";
exit();
}
?>
Server
<?php
require_once("nuSOAP/lib/nusoap.php");
$namespace = "http://localhost/server/server2.php";
// create a new soap server
$server = new soap_server();
// configure our WSDL
$server->configureWSDL("HelloExample");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;
//Register a method that has parameters and return types
$server->register(
// method name:
'HelloWorld',
// parameter list:
array('name'=>'xsd:string'),
// return value(s):
array('return'=>'xsd:string'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'Simple Hello World Method');
//Create a complex type
$server->wsdl->addComplexType(
'MyComplexType',
'complexType',
'struct',
'all',
'',
array(
'ID' => array(
'name' => 'ID',
'type' => 'xsd:int'
),
'YourName' => array(
'name' => 'YourName',
'type' => 'xsd:string'
)
)
);
//Register our method using the complex type
$server->register(
// method name:
'HelloComplexWorld',
// parameter list:
array('name'=>'tns:MyComplexType'),
// return value(s):
array('return'=>'tns:MyComplexType'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'Complex Hello World Method');
//Our Simple method
function HelloWorld($name)
{
return "Hello " . $name;
}
//Our complex method
function HelloComplexWorld($mycomplextype)
{
return $mycomplextype;
}
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>
OUTPUT
Array
(
[ID] => 1234
[YourName] =>
)
Got it right using the following as parameter,
$MyComplexType = array('ID' => $id ,'YourName' => "Jon Postel");
This gives
Array
(
[ID] => 1234
[YourName] => "Jon Postel"
)
Related
I am stuck in a situation where I am unable to send multi-response not array type using soapval(nusoap). I looking for a solution to make struct which accepts multi-request and send multi-response in nusoap. I saw a lot of examples where I only saw the response as an array this is the main issue I think so.
Let me show you my code
$server->wsdl->addComplexType(
'InitiateHolidayDataTransferResult',
'complexType',
'struct',
'sequence',
'',
array( 'HOLIDAY_COMPLEX_TYPE_RES' => array(
'name' => 'HOLIDAY_COMPLEX_TYPE_RES', 'type' => 'tns:HOLIDAY_COMPLEX_TYPE_RES' ,'minOccurs' => '0', 'maxOccurs' => 'unbounded' )
)
);
$server->wsdl->addComplexType(
'HOLIDAY_COMPLEX_TYPE_RES',
'complexType',
'struct',
'all',
'',
array( 'STATUS' => array('name' => 'STATUS','type' => 'xsd:string'),
'STATUS_DESC' => array('name' => 'STATUS_DESC','type' => 'xsd:string')
));
// Register the method to expose
$server->register('HOLIDAY_INFORMATION_DATA', // method name
array('name' => 'tns:HOLIDAY_COMPLEX_TYPE_REQ'), // input parameters
array('return' => 'tns:HOLIDAY_COMPLEX_TYPE_RES'), // output parameters
'urn:HOLIDAY_SERVER1', // namespace
'urn:HOLIDAY_SERVER1#HOLIDAY_INFORMATION_DATA', // soapaction
'document', // style
'encoded', // use
'Holiday Information Get Method' // documentation
);
// Define the method as a PHP function
function HOLIDAY_INFORMATION_DATA($mycomplextype) {
$holiday_data_success='';
// trying to send multi reponse in many ways see below
foreach($mycomplextype as $key=>$val){
//one way
$parm = array();
$parm[] = array('STATUS'=>"Success", "STATUS_DESC"=>"-Holiday Added");
$parm[] = array('STATUS'=>"Success", "STATUS_DESC"=>"-Holiday Added");
$parm[] = array('STATUS'=>"Success", "STATUS_DESC"=>"-Holiday Added");
$holiday_data_success = new soapval('return', 'tns:HOLIDAYRES_COMPLEX_TYPE_RES', $parm);
//second way
$arr = array("STATUS"=>"12345", "STATUS_DESC"=>"Test heading",);
$arr2 = array("STATUS"=>"12346", "STATUS_DESC"=>"Test heading");
$holiday_data_success = array($arr, $arr2);
// third way
$holiday_data_success=[];
$holiday_data_success[] = new soapval('return', 'tns:InitiateHolidayRESTransferResult', array('STATUS'=>"Success", "STATUS_DESC"=>$successtr."-Holiday Added"));
} // end foreach
return $holiday_data_success;
}
// but nothing is working
I am unable to send multi-response for each record that I insert in db
I am writing a simple web service methods using nusoap library in php.
I already create a complextype (struct) in server side but I want to instantiate that struct in a method so I can return it. I saw an example in here but using keyword "new" doesn't work. It doesn't see ComplexType.
So how can I create new ComplexLogin struct in my LoginTest function?
//ComplexLoginType
$server->wsdl->addComplexType('ComplexLogin','complexType','struct','all','',
array(
'EnterpriseId' => array('name' => 'EnterpriseId','type' => 'xsd:int'),
'FirstName' => array('name' => 'FirstName','type' => 'xsd:string'),
'Password' => array('name' => 'Password','type' => 'xsd:string'))
);
$server->register(
// method name:
'LoginTest',
// parameter list:
array('name'=>'tns:ComplexLogin'),
// return value(s):
array('return'=>'tns:ComplexLogin'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'Login Method'
);
I cannot instantiate ComplexType directly but if I use array instead, it works correctly.
However I wonder if there is another way to return ComplexType without using arrays?
My complete working function in server side;
function LoginTest($mycomplexlogin)
{
$conn=openConnection();
// Check connection
if ($conn->connect_error)
{
//return("Connection failed: " . $conn->connect_error);
return NULL;
}
$EnterpriseId=mysqli_real_escape_string($conn,$mycomplexlogin["EnterpriseId"]);
$FirstName=mysqli_real_escape_string($conn,$mycomplexlogin["FirstName"]);
$Password=mysqli_real_escape_string($conn,$mycomplexlogin["Password"]);
$result=array('EnterpriseId'=>$EnterpriseId, 'FirstName'=>$FirstName,'Password'=>$Password);
return $result;
}
I am pulling some emails from my mail server. There is a function should pull these emails and return a multidimensional array. I use this array in client web server to do the job for me. I don't know how to pass this array to the soap complexType. I wrote the following code:
$server->wsdl->addComplexType(
'MailTicket',
'complexType',
'struct',
'all',
'',
array(
'attachment' => array('name' => 'attachment', 'type' => 'xsd:string'),
'body' => array('name' => 'body', 'type' => 'xsd:string'),
'accountID' => array('name' => 'accountID', 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'MailTicketReturn',
'complexType',
'struct',
'all',
'',
array(
'Done' => array('name' => 'result', 'type' => 'xsd:string')
)
);
// Register the method to expose
$server->register('createMailTicket', // method name
array('mailTicketData' => 'tns:MailTicket'), // input parameters
array('return' => 'tns:MailTicketReturn'), // output parameters
'urn:eticketing', // namespace
'urn:eticketing#createMailTicket', // soapaction
'rpc', // style
'encoded', // use
'create a ticket by mail' // documentation
);
and on the client, I wrote:
require_once('nusoap.php');
$wsdlURL="http://127.0.0.1/eticket/ETKWS.php?wsdl";
$client = new nusoap_client($wsdlURL,true);
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$finalArray=Array
(
[attachment] => Array
(
[0] => Array
(
[0] => file1
[1] => file2
)
[1] => Array
(
[0] => file1x
)
)
[body]=>Array
(
[0] => some text
[1] => some other text
)
[accountID] => Array
(
[0] => 5464654
[1] => 4654664
)
)
if(is_array($finalArray)) // creat new tickets
{
$result=$client->call('createMailTicket',$finalArray);
}
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
I got this error:
Constructor error
XML error parsing SOAP payload on line 1: Not well-formed (invalid token)
NuSOAP support return multidimensional array (xsd:Array)
$server= new nusoap_server();
$namespace = "http://localhost/webservice/";
// create a new soap server
$server = new nusoap_server();
// configure our WSDL
$server->configureWSDL("WebServices212");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;
$server->register(
// method name:
'test',
// parameter list:
array('id'=>'xsd:int'),
// return value(array()):
array('return'=>'xsd:Array'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style: rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'documentation');
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA'])
? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
Client
client=new nusoap_client("http://localhost/webservice /webservices.php?wsdl");
$client->setCredentials("webadmin","****");
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $client->call('test', array('id' => '1'));
print_r($result);
if you consume the webservices from PHP no problem, but in other languages there are compatibility problems
I would like to query some stuffs via SOAP by generating WSDL with NuSOAP.
I know there are lots of questions related to the topic, but I didn't have success to adapt the codes to my particular problem.
I was successful in generating WSDL code which returns just an array of structs (associative array), BUT I would rather like to return an object (struct) which contains an integer variable, a string variable AND an array of structs.
So, this is the code that works for returning an array of structs:
<?php
function getStuffs( $user='', $pass='' ) {
// here we can check user and pass and do whatever (if it isn't alright, we can throw exception or return NULL or sg. similar)
// .......
$stuff_array = array();
$stuff_array[] = array( 'id'=>122, 'name'=>'One stuff');
$stuff_array[] = array( 'id'=>213, 'name'=>'Another stuff');
$stuff_array[] = array( 'id'=>435, 'name'=>'Whatever stuff');
$stuff_array[] = array( 'id'=>65, 'name'=>'Cool Stuff');
$stuff_array[] = array( 'id'=>92, 'name'=>'Wow, what a stuff');
return $stuff_array;
}
require_once 'nusoap/lib/nusoap.php';
$server = new soap_server;
// $myNamespace = $_SERVER['SCRIPT_URI'];
$myNamespace = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$server->configureWSDL('MyStuffService', 'urn:' . $myNamespace);
// $server->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/';
$server->wsdl->addComplexType(
// name
'Stuffs',
// typeClass (complexType|simpleType|attribute)
'complexType',
// phpType: currently supported are array and struct (php assoc array)
'struct',
// compositor (all|sequence|choice)
'all',
// restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
'',
// elements = array ( name = array(name=>'',type=>'') )
array(
'id' => array(
'name' => 'id',
'type' => 'xsd:int'
),
'name' => array(
'name' => 'name',
'type' => 'xsd:string'
)
)
);
$server->wsdl->addComplexType(
// name
'StuffsArray',
// typeClass (complexType|simpleType|attribute)
'complexType',
// phpType: currently supported are array and struct (php assoc array)
'array',
// compositor (all|sequence|choice)
'',
// restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
'SOAP-ENC:Array',
// elements = array ( name = array(name=>'',type=>'') )
array(),
// attrs
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:Stuffs[]'
)
),
// arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
'tns:Stuffs'
);
$server->register(
// string $name the name of the PHP function, class.method or class..method
'getStuffs',
// array $in assoc array of input values: key = param name, value = param type
array(
'user' => 'xsd:string',
'pass' => 'xsd:string'
),
// array $out assoc array of output values: key = param name, value = param type
array(
'return' => 'tns:StuffsArray'
),
// mixed $namespace the element namespace for the method or false
'urn:' . $myNamespace,
// mixed $soapaction the soapaction for the method or false
'urn:' . $myNamespace . "#getStuffs",
// mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
'rpc',
// mixed $use optional (encoded|literal) or false
'encoded',
// string $documentation optional Description to include in WSDL
'Fetch array of Stuffs ("id", "name").' // documentation
);
#$server->wsdl->schemaTargetNamespace = $myNamespace;
$server->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
exit();
?>
In a C# Console Application, after adding a Web Reference called "StuffService" with the "?wsdl" appended to the appropriate URL where this PHP-file can be found, this code works, I can perfectly query the stuff_array values like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebServiceTest
{
class Program
{
static void Main(string[] args)
{
StuffService.MyStuffService myService = new StuffService.MyStuffService();
StuffService.Stuffs[] stuffs = myService.getStuffs("someone", "1234");
foreach (var stuff in stuffs)
{
Console.WriteLine(stuff.id+".: "+stuff.name);
}
Console.WriteLine();
Console.WriteLine("Press a key...");
Console.ReadKey();
}
}
}
That's cool, BUT I'd like to develop this code to give back an object like this:
class ResponseObject {
public $responseCode = 0;
public $responseMessage = '';
public $stuffArray = NULL;
}
$responseObject = NULL;
function getStuffs( $user='', $pass='' ) {
global $responseObject;
$responseObject = new ResponseObject();
// check stuffs in a simple way now
if($user != 'someone' && $pass != '1234'){
$responseObject->responseCode = 2;
$responseObject->responseMessage = 'Authentication failed';
return $responseObject;
}
$responseObject->stuffArray = array();
$responseObject->stuffArray[] = array( 'id'=>122, 'name'=>'One stuff');
$responseObject->stuffArray[] = array( 'id'=>213, 'name'=>'Another stuff');
$responseObject->stuffArray[] = array( 'id'=>435, 'name'=>'Whatever stuff');
$responseObject->stuffArray[] = array( 'id'=>65, 'name'=>'Cool Stuff');
$responseObject->stuffArray[] = array( 'id'=>92, 'name'=>'Wow, what a stuff');
$responseObject->responseCode = 1;
$responseObject->responseMessage = 'Successful!';
return $responseObject;
}
What's the appropriate NuSOAP code for that?
Thanks!! :)
I hope I could clarify what I would like to achieve: returning a struct which contains an int, a string and an array of structs, but don't know how to write the appropriate NuSOAP-code for that. This way I could firstly check the responseCode, and handle it with the appropriate error messages OR outputting the stuffArray, etc.
After long hours of experimentation, I found the solution!
So giving back a structure containing three members - an int responseCode, a string responseMessage and an array of structs called stuffArray in the example - via SOAP with NuSOAP (PHP) looks like this below, I put some comments in the code to make it more unambiguous:
<?php
class ResponseObject {
public $responseCode = 0;
public $responseMessage = 'Unknown error!';
public $stuffArray = NULL;
}
/**
* #return object
*/
function getStuffs( $user='', $pass='' ) {
$responseObject = new ResponseObject();
// check stuffs in a simple way now
if( !($user == 'someone' and $pass == '1234') ){
$responseObject->responseCode = 2;
$responseObject->responseMessage = 'Authentication failed!';
return $responseObject;
}
$responseObject->stuffArray = array();
$responseObject->stuffArray[] = array( 'id'=>122, 'name'=>'One stuff');
$responseObject->stuffArray[] = array( 'id'=>213, 'name'=>'Another stuff');
$responseObject->stuffArray[] = array( 'id'=>435, 'name'=>'Whatever stuff');
$responseObject->stuffArray[] = array( 'id'=>65, 'name'=>'Cool Stuff');
$responseObject->stuffArray[] = array( 'id'=>92, 'name'=>'Wow, what a stuff');
$responseObject->responseCode = 1;
$responseObject->responseMessage = 'Successful!';
return $responseObject;
}
require_once 'nusoap/lib/nusoap.php';
$server = new soap_server;
// $myNamespace = $_SERVER['SCRIPT_URI'];
$myNamespace = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$server->configureWSDL(
// string $serviceName, name of the service
'MyStuffService',
// mixed $namespace optional 'tns' service namespace or false
// 'urn:' . $myNamespace
$myNamespace
);
// $server->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/';
$server->wsdl->schemaTargetNamespace = $myNamespace;
$server->wsdl->addComplexType(
// name
'Stuffs',
// typeClass (complexType|simpleType|attribute)
'complexType',
// phpType: currently supported are array and struct (php assoc array)
'struct',
// compositor (all|sequence|choice)
'all',
// restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
'',
// elements = array ( name = array(name=>'',type=>'') )
array(
'id' => array(
'name' => 'id',
'type' => 'xsd:int'
),
'name' => array(
'name' => 'name',
'type' => 'xsd:string'
)
)
);
$server->wsdl->addComplexType(
// name
'StuffsArray',
// typeClass (complexType|simpleType|attribute)
'complexType',
// phpType: currently supported are array and struct (php assoc array)
'array',
// compositor (all|sequence|choice)
'',
// restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
'SOAP-ENC:Array',
// elements = array ( name = array(name=>'',type=>'') )
array(),
// attrs
array(
array(
'ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:Stuffs[]'
)
),
// arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
'tns:Stuffs'
);
$server->wsdl->addComplexType(
// name
'ResponseObject',
// typeClass (complexType|simpleType|attribute)
'complexType',
// phpType: currently supported are array and struct (php assoc array)
'struct',
// compositor (all|sequence|choice)
'all',
// restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
'',
// elements = array ( name = array(name=>'',type=>'') )
array
(
'responseCode' => array( 'type' => 'xsd:int'),
'responseMessage' => array( 'type' => 'xsd:string'),
'stuffArray' => array( 'type' => 'tns:StuffsArray'
// DON'T UNCOMMENT THE FOLLOWING COMMENTED LINES, BECAUSE THIS WAY IT DOESN'T WORK!!! - Left it in the code not to forget it....
// ,
// 'minOccurs' => '0',
// 'maxOccurs' => 'unbounded'
)
)
);
$server->register(
// string $name the name of the PHP function, class.method or class..method
'getStuffs',
// array $in assoc array of input values: key = param name, value = param type
array(
'user' => 'xsd:string',
'pass' => 'xsd:string'
),
// array $out assoc array of output values: key = param name, value = param type
array(
'return' => 'tns:ResponseObject'
),
// mixed $namespace the element namespace for the method or false
// 'urn:' . $myNamespace,
$myNamespace,
// mixed $soapaction the soapaction for the method or false
// 'urn:' . $myNamespace . "#getStuffs",
$myNamespace . "#getStuffs",
// mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
'rpc',
// mixed $use optional (encoded|literal) or false
'encoded',
// string $documentation optional Description to include in WSDL
'Fetch array of Stuffs ("id", "name").' // documentation
);
// $server->wsdl->schemaTargetNamespace = $myNamespace;
// function def.: nusoap/lib/class.soap_server.php (236)
$server->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '');
// DON'T UNCOMMENT THE FOLLOWING LINES!! - Don't call these headers explicitly,
// everything will be handled in function service() appropriately - I know it by experience that it's not a good choice...
// output:wsdl
// header('Content-Type: text/xml;charset=utf-8');
// header('Content-Type: text/xml');
// echo $server->wsdl->serialize();
exit(0);
Give this file a name, for example getStuffComplex.php, and then copy this file somewhere on your webserver, and remember its path.
For example one domain name on my local webserver is http://soap.local, and the above mentioned PHP-code can be reached at http://soap.local/getStuffComplex.php.
Let's say you want to call getStuffs() function in a C# code via a SOAP client, from a Console Application under Visual Studio 2010. In this case you have to do the following steps:
Create a new Console Application project
Right click "References" - "Add Service Reference"
Click "Advanced..."
Click "Add Web Reference..."
Paste the path of the previously saved PHP-file's URL (with the content above) and append the "?wsdl" string in the URL field. For example in my case: http://soap.local/getStuffComplex.php?wsdl
Click the green right arrow ("Go") or hit Enter after fill out URL field. If getStuff() method is found, the situation is hopeful.
Give the reference a name on the right side (Web reference name), for example "StuffServiceComplex" (I will use this name in my code), than hit Enter. Now you have to see it under "Web References".
Copy the code below into Program.cs, and test it by hitting F5 or clicking the green "play" icon.
The C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;
namespace WebServiceTestComplex
{
class Program
{
static void Main(string[] args)
{
try
{
StuffServiceComplex.MyStuffService myService = new StuffServiceComplex.MyStuffService();
StuffServiceComplex.ResponseObject myRespObject = myService.getStuffs("someone", "1234");
switch (myRespObject.responseCode)
{
// Everything was OK, results can be output
case 1:
Console.WriteLine("Everything's OK, let's write the results to the standard output:");
foreach (var stuff in myRespObject.stuffArray)
{
Console.WriteLine("\t"+stuff.id + ".:\t" + stuff.name);
}
break;
// Authentication failed
case 2:
// Unknown error
case 0:
default:
Console.WriteLine("Error:");
Console.WriteLine("\tError code: "+myRespObject.responseCode);
Console.WriteLine("\tError message: " + myRespObject.responseMessage);
break;
}
}
catch (SoapException e)
{
Console.WriteLine("=== SOAP EXCEPTION!! ===");
Console.WriteLine(e);
}
catch (Exception e)
{
Console.WriteLine("=== OTHER EXCEPTION!! ===");
Console.WriteLine(e.ToString());
}
Console.WriteLine();
Console.WriteLine("Press a key...");
Console.ReadKey();
}
}
}
The output:
Everything's OK, let's write the results to the standard output:
122.: One stuff
213.: Another stuff
435.: Whatever stuff
65.: Cool Stuff
92.: Wow, what a stuff
Press a key...
I hope this helps someone who struggled with bringing PHP and SOAP and .NET together.
(Note: take care about character coding when using accents or any special letters. By default, ANSI could be used (but character encodings have to be the same).)
I am working with nuSoap to build a soap server.
But i cant get the attributes the way i want.
I would like as return value:
<return xsi:type="tns:Taxatie">
<EmailAdres OptIn="1" xsi:type="tns:string">email#domain.com</EmailAdres>
</return>
And i get:
<return xsi:type="tns:Taxatie">
<EmailAdres OptIn="1" xsi:type="tns:EmailAdres">
<EmailAdres xsi:type="xsd:string">email#domain.com</EmailAdres>
</EmailAdres>
</return>
anyone know what i must change?
Or how I should set up the arrays?
This is my test code:
<?php
require_once("nusoap.php");
$soapserver = new nusoap_server();
$soapserver->configureWSDL('thijs.test', 'urn:thijs.test');
$soapserver->wsdl->addComplexType(
'Taxatie',
'complexType',
'struct',
'all',
'',
array(
'EmailAdres' => array('name' => 'EmailAdres', 'type' => 'tns:EmailAdres')
)
);
$soapserver->wsdl->addComplexType(
'EmailAdres',
'simpleType',
'struct',
'all',
'',
array(
"EmailAdres" => array('name' => 'EmailAdres', 'type' => 'xsd:string', 'minOccurs' => 0)
),
array(
'OptIn' => array('name' => 'OptIn', 'type' => 'xsd:boolean', 'use' => 'required')
)
);
$soapserver->register('taxatie', // method name
array(), // input parameters
array('return' => 'tns:Taxatie'), // output parameters
'urn:thijs.test', // namespace
'urn:thijs.test#taxatie', // soapaction
'rpc', // style
'encoded', // use
'return something' // documentation
);
class taxatie
{
var $EmailAdres = null;
function taxatie()
{
$this->EmailAdres = new emailadres();
}
}
class emailadres
{
var $EmailAdres = 'email#domain.com';
var $OptIn = true;
}
function taxatie()
{
return new taxatie();
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$soapserver->service($HTTP_RAW_POST_DATA);
Thanks in advance
Why not simply return an array instead of using complex type?
e.g
$resultarray['taxatie'] = array(
'EmailAdres' => $row["EmailAdres"],
'tagcount' => $row["tagcount"],
'OptIn' => $row["OptIn"]
);