Looking for WebServices Example

Notice: This thread is very old.
unagi2020
Member | 18
+
0
-

Hello,
Thanks for creating such a wonderful framework. I am planning to use this for a large project which involves replacing Controller classes with Web Services. Can you guys provide me with an example on how this can be done in a better way?

Thanks in advance,
Unagi

HosipLan
Moderator | 4668
+
0
-

Please can you clear what do you mean specifically by “Web Services” ?

joseff
Member | 233
+
0
-

I also don't understand well, please be more specific.

unagi2020
Member | 18
+
0
-

Sorry for not being very specific. I want to expose certain methods from Presenter layer to other applications using WSDL over SOAP without exposing all methods. Is there a way in Nette where I can mark the methods which I want to expose ?

For e.g. my Presenter layer has following two methods

protected function createUserForm()
{
	...
}

public function createUser()
{
	...
}

I just want to expose createUser function from the presenter to service using following code

ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer('UserService.wsdl');


try {
	$server->setClass("UserPresenter");
	$server->handle();
}catch (UserException $e) {
	$e->soapFault();
}catch (Exception $e) {
	$server->fault($e->getCode(), $e->getMessage(), null, null);
}

Thanks in advance for the help.

Last edited by unagi2020 (2010-12-07 20:28)

mcmatak
Member | 504
+
0
-

I am afraid you must create WSDL to expose some functions, but unfortunately there is no layer for Soap in Nette. On the other side you can use Zend Soap Autodiscover, which can be combinated with Nette. Also Zend Soap Server is not bad, but it has a lot of problems with namespaces,

maybe WSO2 there is problem with price I thing.

I would like to see your solution I am also interested.

HosipLan
Moderator | 4668
+
0
-

I have to disappoint you, I don't think anyone is using presenters in this way.
I'm not saing it can't be done, It would take some time to figure it out,
but I'm not sure this is the best way to solve it

HosipLan
Moderator | 4668
+
0
-

I just went through series of ideas how to make this work. The last one i'm gonna share with you, and probably the best one, is to extend SoapServer and modificate it's behaviour to act like real Nette router.


//edit:
It's just an idea, but there should be way to make extended SoapServer just handle the request and translate it somehow. So you can use this part in router, and in next step to make it create and send valid response at the end of presenter life-cycle. It would require changes in presenter, to check whether it is soap or not, to switch templates for output, and some other hooks, but i think this could be it.

Last edited by HosipLan (2010-12-08 18:18)

mcmatak
Member | 504
+
0
-

firstly there is two problems:

  1. map functions to some receipt for client (WSDL)
  2. map requests set in WSDL to functions

at the end define new data types like special Exceptions

and last be careful about the security (only specified functions can be available by services – SOAP)

there is solution

  1. Zend_Soap_Autodiscover
  2. Zend_Soap_Server

very bad support for namespaces, better say no support

there is nothing in Nette, maybe someone can be inspired by 1, 2 Zend solutions and rewrite it for Nette and namespaces and robotloader for autodiscovering etc.

any volunteer?

HosipLan
Moderator | 4668
+
0
-

I've already made “Autodiscover” for presenters on Nette robot loader with cache https://forum.nette.org/…z-dost-narku I think that the output can be very easily transformed to wsdl

Last edited by HosipLan (2010-12-08 19:17)

unagi2020
Member | 18
+
0
-

Thanks for the response. I know Yii Framework (http://www.yiiframework.com/…s.webservice#…) does Auto Discover functionality very nicely. Not worked using NameSpaces though.

I bumped into Nette couple of day earlier after using at least using 10 frameworks and immediately felt in love with it even though I do not understand a single word of Czech.

Love this framework.

Will try to work on Auto Discover part once I finish by framework discovery part.

Again thanks for taking time and helping me out.

unagi2020
Member | 18
+
0
-

Has anyone implemented Rest Web Services using version 2.0 ? A small sample would be very nice.

daliborcaja
Member | 57
+
0
-

I think that methods called via webservice are usually model methods. If you want to send only objects returned by model (e.g. dibirow) via webservice, I would recommend you to add methods which would call only their own methods in model to the class webservice, this would simply ensure the access to the selected methods. Here you can add authorization, too.

mcmatak
Member | 504
+
0
-

why are you still wanting to map nette presenter? why not use standard method

<?php

namespace ServicesModule;

require_once 'Zend/Soap/AutoDiscover.php';
require_once 'Zend/Soap/Server.php';


final class DefaultPresenter extends BasePresenter
{

	public function actionDefault()
	{
		if (isset($_GET['wsdl'])) {
			$autodiscover = new \Zend_Soap_AutoDiscover();
			$autodiscover->setClass("ServicesModule_DefaultModel");
			$autodiscover->handle();

		}
		else {
			$server = new \Zend_Soap_Server('http://' .$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "?wsdl");
			$server->setClass('ServicesModule_DefaultModel');
			$server->registerFaultException(array('SSCAuthException', 'SSCVerificationException', 'SSCException'));
			$server->handle();

		}
	}


}
?>
daliborcaja
Member | 57
+
0
-

mcmatak napsal(a):

why are you still wanting to map nette presenter? why not use standard method

exactly

worsik
Member | 40
+
0
-

mcmatak wrote:


maybe WSO2 there is problem with price I thing.

Do you have some experience with this Framework? I'm trying to use it, but I found few errors.
I'm new to web services and I need to write both server and client, each with different WSDL files (It's two-way communication with an external application).
Actualy I'm now (only for testing) providing 2 servers and 2 clients.

Problem is, that when I send request from client to server, server can handle data, but when server creates output object and returns it, client gets only empty object.
I found, that constructor of output object is called TWICE… Once when server is creating object (that's right) but when operation ends with return(‘result’ ⇒ $output), somewher the constructor is called again.
Because I need to fill object with data, I'm creating empty object and then filling it.
When I change constructor to create non-empty object with default values and edit them, client get object with default vaules.

I'm hardly trying to find a reason for this behavior, but no luck.

Can somebody help?
WSDL documents are too big to paste here, I'm pretty sure, that they are OK.
Maybe I'm using Framework wrong…