f00b4r / nusoap

:smirk: Fixed NuSOAP for PHP 5.6 - 8.2
https://f00b4r.github.io/nusoap/
320 stars 356 forks source link

With Laravel way to call function inside register from a controller method #18

Closed wa05 closed 5 years ago

wa05 commented 7 years ago
$server = new \nusoap_server();
$server->configureWSDL('TestService', false, url('ws/connect'));

$server->register('test',
            [
                'input' => 'xsd:string'
            ],
            [
                'output' => 'xsd:string'
            ],
            'http://192.168.0.21:88/wms/public/ws/',
            'outcome',
            "rpc",
            "encoded",
            "Cotizacion de un vehiculo");

$rawPostData = file_get_contents("php://input");

return \Response::make($server->service($rawPostData), 200, array('Content-Type' => 'text/xml; charset=ISO-8859-1'));

Is there a way to place test inside the controller??

f3l1x commented 6 years ago

Hi. Thanks for an issue.

I do not known how to help you. What kind of problem do you have?

wa05 commented 6 years ago

When you use the register function the first parameter is a string, that string is the method that you will implement, how you can point that string to a method from the same controller that were you are instanciating the web server ...

Now I'm using a helpers file but I'm trying to make it more "elegantly"..

f3l1x commented 6 years ago

Well, I've found this thread https://stackoverflow.com/a/8094692.

// register the class method and the params of the method
$server->register("myClass.ShowString"                       
                 ,array('name'=>'xsd:string')
                 ,array('return'=>'xsd:string')
                 ,$namespace,false
                 ,'rpc'
                 ,'encoded'
                 ,'Sample of embedded classes...' 
                                );
wa05 commented 6 years ago

Finally I solved adding a global helper file to the composer.json and Laravel encounters the method in that file

Alvax500-debug commented 4 years ago

Hi wa05, you have some example of your solution? please i have exactly the same problem right now u.u,

wa05 commented 4 years ago
Route::any('ws-delos', 'WebService\WsController@connect');

public function connect() { try {

        $server = new \nusoap_server();
        $server->configureWSDL('WMS', "urn:delos", url('ws-delos'), 'rpc');

        $this->server = $server;

        $this->server->wsdl->addComplexType(
            'item',
            'complexType',
            'struct',
            'all',
            '',
            [
                'codigoMaterial' => [
                    'name' => 'codigoMaterial', 'type' => 'xsd:string'
                ],
                'cantidad' => [
                    'name' => 'cantidad', 'type' => 'xsd:int'
                ],
                'nroTransaccion' => [
                    'name' => 'nroTransaccion', 'type' => 'xsd:int'
                ],
                'codigoInterno' => [
                    'name' => 'codigoInterno', 'type' => 'xsd:int'
                ]
            ]
        );

        $this->server->register('DocumentoEgreso_Agregar',
            [
                'empresa' => 'xsd:int',
                'nroPedido' => 'xsd:string',
                'cliente' => 'xsd:string',
                'codigoTransportista' => 'xsd:int',
                'descripcionTransportista' => 'xsd:string',
                'items' => 'tns:listaEgreso'
            ],
            [
                'output' => 'xsd:string'
            ],
            "urn:delos",
            "urn:delos#DocumentoEgreso_Agregar",
            "rpc",
            'encoded',
            "Circuito Comercial - Recibe la tarea y la graba en estado pendiente");

    } catch (Exception $e) {
        return response('ERROR ' . $e->getMessage());
    }

    $rawPostData = file_get_contents("php://input");

    return response($this->server->service($rawPostData), 200)
        ->header('Content-Type', 'text/xml')
        ->header('charset', 'ISO-8859-1');
}

composer.json
`
 "autoload": {
    "classmap": [
      "database/seeds",
      "database/factories"
    ],
    "files": [
      "app/helper.php"
    ],
`
wa05 commented 4 years ago

composer.json "autoload": { "classmap": [ "database/seeds", "database/factories" ], "files": [ "app/helper.php" ],

web.php Route::any('ws-delos', 'WebService\WsController@connect');

controller ` public function connect() { try {

        $server = new \nusoap_server();
        $server->configureWSDL('WMS', "urn:delos", url('ws-delos'), 'rpc');

        $this->server = $server;

        $this->server->wsdl->addComplexType(
            'item',
            'complexType',
            'struct',
            'all',
            '',
            [
                'codigoMaterial' => [
                    'name' => 'codigoMaterial', 'type' => 'xsd:string'
                ],
                'cantidad' => [
                    'name' => 'cantidad', 'type' => 'xsd:int'
                ],
                'nroTransaccion' => [
                    'name' => 'nroTransaccion', 'type' => 'xsd:int'
                ],
                'codigoInterno' => [
                    'name' => 'codigoInterno', 'type' => 'xsd:int'
                ]
            ]
        );

        $this->server->register('DocumentoEgreso_Agregar',
            [
                'empresa' => 'xsd:int',
                'nroPedido' => 'xsd:string',
                'cliente' => 'xsd:string',
                'codigoTransportista' => 'xsd:int',
                'descripcionTransportista' => 'xsd:string',
                'items' => 'tns:listaEgreso'
            ],
            [
                'output' => 'xsd:string'
            ],
            "urn:delos",
            "urn:delos#DocumentoEgreso_Agregar",
            "rpc",
            'encoded',
            "Circuito Comercial - Recibe la tarea y la graba en estado pendiente");

    } catch (Exception $e) {
        return response('ERROR ' . $e->getMessage());
    }

    $rawPostData = file_get_contents("php://input");

    return response($this->server->service($rawPostData), 200)
        ->header('Content-Type', 'text/xml')
        ->header('charset', 'ISO-8859-1');
}`

helper.php `function DocumentoEgreso_Agregar($empresa, $nroPedido, $cliente, $codigoTransportista, $descripcionTransportista, $items, $codigoLugarEnvio = null) { $controller = app('app\Http\Controllers\WebService\WsController');

return $controller->wsEgresoData($empresa, $nroPedido, $cliente,
                $codigoTransportista, $descripcionTransportista, $items, $codigoLugarEnvio);

} `

Alvax500-debug commented 4 years ago

thank you so much wa05 you save my ass, a great contribution

GermanZun commented 3 years ago

thanks you @wa05 !

excalibur1028 commented 3 years ago

Hi, would like to know on how did you define the code below on the register function. Thanks

'items' => 'tns:listaEgreso' ->> listaEgreso class where did you define it? inside the controller?

wa05 commented 3 years ago

@excalibur1028 excuse me for the slow response... Its defined in the controller... as a complexType

$this->server->wsdl->addComplexType( 'listaEgreso', 'complexType', 'array', '', 'SOAP-ENC:Array', [], [ [ 'ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:item[]' ] ], 'tns:item' );