Php webservice soap wsdl

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Pure PHP implementation of SOAP 1.1 and 1.2 server

License

goetas-webservices/soap-server

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP implementation of SOAP 1.1 and 1.2 server specifications.

  • Pure PHP, no dependencies on ext-soap
  • Extensible (JMS event listeners support)
  • PSR-7 HTTP messaging
  • PSR-15 HTTP server handlers
  • No WSDL/XSD parsing on production
  • IDE type hinting support

Only document/literal style is supported and the webservice should follow the WS-I guidelines.

There are no plans to support the deprecated rpc and encoded styles. Webservices not following the WS-I specifications might work, but they are officially not supported.

goetas-webservices/soap-server-demo is a demo project that shows how to produce a SOAP server in a generic PHP web application.

The recommended way to install goetas-webservices / soap-server is using Composer:

Add this packages to your composer.json file.

To improve performance, this library is based on the concept that all the SOAP/WSDL metadata has to be compiled into PHP compatible metadata (in reality is a big plain PHP array, so is really fast).

To do this we have to define a configuration file (in this case called config.yml ) that holds some important information.

# config.yml soap_server: namespaces: 'http://www.example.org/test/': 'TestNs/MyApp' destinations_php: 'TestNs/MyApp': soap/src destinations_jms: 'TestNs/MyApp': soap/metadata aliases: 'http://www.example.org/test/': MyCustomXSDType: 'MyCustomMappedPHPType' metadata: 'test.wsdl': ~

This file has some important sections:

  • metadata specifies where are placed WSDL files that will be used to generate al the required PHP metadata.
  • namespaces (required) defines the mapping between XML namespaces and PHP namespaces. (in the example we have the http://www.example.org/test/ XML namespace mapped to TestNs\MyApp )
  • destinations_php (required) specifies the directory where to save the PHP classes that belongs to TestNs\MyApp PHP namespace. (in this example TestNs\MyApp classes will ne saved into soap/src directory.
  • destinations_jms (required) specifies the directory where to save JMS Serializer metadata files that belongs to TestNs\MyApp PHP namespace. (in this example TestNs\MyApp metadata will ne saved into soap/metadata directory.
  • aliases (optional) specifies some mappings that are handled by custom JMS serializer handlers. Allows to specify to do not generate metadata for some XML types, and assign them directly a PHP class. For that PHP class is necessary to create a custom JMS serialize/deserialize handler.

In order to be able to use the SOAP server we have to generate some metadata and PHP classes.

bin/soap-server generate \ tests/config.yml \ --dest-class=GlobalWeather/Container/SoapServerContainer \ soap/src-gw/Container
  • bin/soap-server generate is the command we are running
  • tests/config.yml is a path to our configuration file
  • —dest-class=GlobalWeather/Container/SoapServerContainer allows to specify the fully qualified class name of the container class that will hold all the webservice metadata.
  • soap/src/Container is the path where to save the container class that holds all the webservice metadata (you will have to configure the auto loader to load it)

Once all the metadata are generated we can use our SOAP server.

Let’s see a minimal example:

// composer auto loader require __DIR__ . '/vendor/autoload.php'; // instantiate the main container class // the name was defined by --dest-class=GlobalWeather/Container/SoapServerContainer // parameter during the generation process $container = new SoapServerContainer(); // create a JMS serializer instance $serializer = SoapContainerBuilder::createSerializerBuilderFromContainer($container)->build(); // get the metadata from the container $metadata = $container->get('goetas_webservices.soap.metadata_reader'); $handler = new class() < function anAction($someParam) < return 'OK 123'; > function someAction($someParam, HeadersIncoming $headersIncoming) < $headers = $headersIncoming->getRawheader(); // perform some checks on $headers here return 'OK 123'; > function anotherAction($someParam, HeadersOutgoing $headersOutgoing) < // reply with custom headers $headersOutgoing->addHeader(new Header(new SomeHeaderData())); // reply with custom headers in pure xml $dom = new DOMDocument(); $dom->appendChild($dom->createElement('foo', 'bar')); $headersOutgoing->addHeader(new Header($dom->documentElement)); return 'OK 456'; > function someErrAction($someParam) < throw new CustomExcpetion(); // converted in a soap fault > >; $router = new DefaultRouter(new ConfiguredRoute($handler)); $factory = new ServerFactory($metadata, $serializer, $router); // get the soap server $server = $factory->getServer('test.wsdl'); // create psr7 request $request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals(); // let the server handle the request $response = $server->handle($request); // send the response to the client (using laminas/laminas-httphandlerrunner) $emitter = new \Laminas\HttpHandlerRunner\Emitter\SapiEmitter(); $emitter->emit($response);

Источник

SOAP

PROBLEM (with SOAP extension under PHP5) of transferring object, that contains objects or array of objects. Nested object would not transfer.

SOLUTION:
This class was developed by trial and error by me. So this 23 lines of code for most developers writing under PHP5 solves fate of using SOAP extension.

/*
According to specific of organization process of SOAP class in PHP5, we must wrap up complex objects in SoapVar class. Otherwise objects would not be encoded properly and could not be loaded on remote SOAP handler.

Function «getAsSoap» call for encoding object for transmission. After encoding it can be properly transmitted.
*/
abstract class SOAPable public function getAsSOAP () foreach( $this as $key =>& $value ) $this -> prepareSOAPrecursive ( $this -> $key );
>
return $this ;
>

private function prepareSOAPrecursive (& $element ) if( is_array ( $element )) foreach( $element as $key =>& $val ) $this -> prepareSOAPrecursive ( $val );
>
$element =new SoapVar ( $element , SOAP_ENC_ARRAY );
>elseif( is_object ( $element )) if( $element instanceof SOAPable ) $element -> getAsSOAP ();
>
$element =new SoapVar ( $element , SOAP_ENC_OBJECT );
>
>
>

class PersonList extends SOAPable protected $ArrayOfPerson ; // variable MUST be protected or public!
>

class Person extends SOAPable //any data
>

$client =new SoapClient ( «test.wsdl» , array( ‘soap_version’ => SOAP_1_2 , ‘trace’ => 1 , ‘classmap’ => array( ‘Person’ => «Person» , ‘PersonList’ => «PersonList» ) ));

$PersonList =new PersonList ;

$client -> someMethod ( $PersonList );

?>

So every class, which will transfer via SOAP, must be extends from class SOAPable.
As you can see, in code above, function prepareSOAPrecursive search another nested objects in parent object or in arrays, and if does it, tries call function getAsSOAP() for preparation of nested objects, after that simply wrap up via SoapVar class.

So in code before transmitting simply call $obj->getAsSOAP()

If you are having an issue where SOAP cannot find the functions that are actually there if you view the wsdl file, it’s because PHP is caching the wsdl file (for a day at a time). To turn this off, have this line on every script that uses SOAP: ini_set(«soap.wsdl_cache_enabled», «0»); to disable the caching feature.

Juste a note to avoid wasting time on php-soap protocol and format support.

Until php 5.2.9 (at least) the soap extension is only capable of understanding wsdl 1.0 and 1.1 format.

The wsdl 2.0, a W3C recommendation since june 2007, ISN’T supported in php soap extension.
(the soap/php_sdl.c source code don’t handle wsdl2.0 format)

The wsdl 2.0 is juste the 1.2 version renamed because it has substantial differences from WSDL 1.1.

The differences between the two format may not be invisible if you don’t care a lot.

The typical error message if you provide a wsdl 2.0 format file :
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn’t find in ‘wsdl/example.wsdl’ in /path/client.php on line 9

Was calling an asmx method like $success=$x->AuthenticateUser($userName,$password) and this was returning me an error.

However i changed it and added the userName and password in an array and its now KAWA.

If anyone is trying to use this for accessing Sabre’s web services, it won’t work. Sabre checks the request header «Content-Type» to see if it is «text/xml» . If it is not text/xml then it sends an error back.

You will need to create a socket connection and use that to send the request over.

Here is an example of a php client talking to a asmx server:

// Prepare SoapHeader parameters
$sh_param = array(
‘Username’ => ‘username’ ,
‘Password’ => ‘password’ );
$headers = new SoapHeader ( ‘http://soapserver.example.com/webservices’ , ‘UserCredentials’ , $sh_param );

// Prepare Soap Client
$soapClient -> __setSoapHeaders (array( $headers ));

// Setup the RemoteFunction parameters
$ap_param = array(
‘amount’ => $irow [ ‘total_price’ ]);

// Call RemoteFunction ()
$error = 0 ;
try <
$info = $soapClient -> __call ( «RemoteFunction» , array( $ap_param ));
> catch ( SoapFault $fault ) <
$error = 1 ;
print( »
alert(‘Sorry, blah returned the following ERROR: » . $fault -> faultcode . «-» . $fault -> faultstring . «. We will now take you back to our home page.’);
window.location = ‘main.php’;
» );
>

if ( $error == 0 ) <
$auth_num = $info -> RemoteFunctionResult ;

// Setup the OtherRemoteFunction() parameters
$at_param = array(
‘amount’ => $irow [ ‘total_price’ ],
‘description’ => $description );

// Call OtherRemoteFunction()
$trans = $soapClient -> __call ( «OtherRemoteFunction» , array( $at_param ));
$trans_result = $trans -> OtherRemoteFunctionResult ;
.
> else <
// Record the transaction error in the database

// Kill the link to Soap
unset( $soapClient );
>
>
>
>

Источник

Читайте также:  Таблицы
Оцените статью