BeSimpleSoap/README.md

125 lines
3.8 KiB
Markdown
Raw Normal View History

2013-10-30 15:54:35 +01:00
# BeSimpleSoap
2013-08-24 17:31:35 +02:00
Build SOAP and WSDL based web services.
This fork from 2017 is a refactored version that fixes a lot of errors and provides
better APi, more robust, stable and modern codebase.
See [How to use](#how-to-use) that will help you to understand the magic.
2013-08-24 17:31:35 +02:00
# Components
BeSimpleSoap consists of five components ...
## BeSimpleSoapClient
2013-08-24 17:31:35 +02:00
**Refactored** BeSimpleSoapClient is a component that extends the native PHP SoapClient with further features like SwA and WS-Security.
2013-08-24 17:31:35 +02:00
## BeSimpleSoapServer
2013-08-24 17:31:35 +02:00
**Refactored** BeSimpleSoapServer is a component that extends the native PHP SoapServer with further features like SwA and WS-Security.
2013-08-24 17:31:35 +02:00
## BeSimpleSoapCommon
**Refactored** BeSimpleSoapCommon component contains functionality shared by both the server and client implementations.
2013-08-24 17:31:35 +02:00
## BeSimpleSoapWsdl
2013-08-24 17:31:35 +02:00
Currently **unsupported!** For further information see the [README](https://github.com/BeSimple/BeSimpleSoap/blob/master/src/BeSimple/SoapWsdl/README.md).
2013-08-24 17:31:35 +02:00
## BeSimpleSoapBundle
2013-08-24 17:31:35 +02:00
Currently **unsupported!**
The BeSimpleSoapBundle is a Symfony2 bundle to build WSDL and SOAP based web services.
For further information see the the original [README](https://github.com/BeSimple/BeSimpleSoap/blob/master/src/BeSimple/SoapBundle/README.md).
*May not work properly since the Symfony libraries were removed.*
2013-08-24 17:31:35 +02:00
# Installation
If you do not yet have composer, install it like this:
```sh
curl -s http://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin
```
Create a `composer.json` file:
```json
{
"require": {
"besimple/soap": "0.2.*@dev"
2013-08-24 17:31:35 +02:00
}
}
```
Now you are ready to install the library:
```sh
php /usr/local/bin/composer.phar install
```
# How to use
You can investigate the unit tests in order to get a clue.
Forget about associative arrays, multiple extension and silent errors!
```
// unit tests for soap client
BeSimple\SoapClient\Tests\SoapClientBuilderTest
// unit tests for soap server
BeSimple\SoapServer\Tests\SoapServerBuilderTest
```
## Small example of soap client call
```php
$soapClientBuilder = new SoapClientBuilder();
$soapClient = $soapClientBuilder->build(
SoapClientOptionsBuilder::createWithDefaults(),
SoapOptionsBuilder::createWithDefaults('http://path/to/wsdlfile.wsdl')
);
$myRequest = new MyRequest();
$myRequest->attribute = 'string value';
$soapResponse = $soapClient->soapCall('myMethod', [$myRequest]);
var_dump($soapResponse); // Contains Response, Attachments
```
### Something wrong?!
Turn on the tracking and catch `SoapFaultWithTracingData` exception to get some sweets :)
```php
try {
$soapResponse = $soapClient->soapCall('GetUKLocationByCounty', [$getUKLocationByCountyRequest]);
} catch (SoapFaultWithTracingData $fault) {
var_dump($fault->getSoapResponseTracingData()->getLastRequest());
}
```
## Small example of soap server handling
Starting a SOAP server is a bit more complex.
I would suggest you to inspect SoapServer unit tests to get complete image.
But don't be scared too much, you just need to create a DummyService that will
handle your client SOAP calls.
```php
$dummyService = new DummyService();
$classMap = new ClassMap();
foreach ($dummyService->getClassMap() as $type => $className) {
$classMap->add($type, $className);
}
$soapServerBuilder = new SoapServerBuilder();
$soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService);
$soapOptions = SoapOptionsBuilder::createWithClassMap($dummyService->getWsdlPath(), $classMap);
$soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions);
$request = $soapServer->createRequest(
$dummyService->getEndpoint(),
'DummyService.dummyServiceMethod',
'text/xml;charset=UTF-8',
'<your><soap><request><here /></request></soap></your>'
);
$response = $soapServer->handleRequest($request);
var_dump($response); // Contains Response, Attachments
```