Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb20bf8

Browse files
author
Roger Webb
committed
Wrapped lines after the first work crossing 72 chars. Changed example to use ob_get_clean().
1 parent f6a8241 commit bb20bf8

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

cookbook/web_services/php_soap_extension.rst

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Create a Web Service with the PHP SOAP Extension in a Symfony2 Controller
22
=========================================================================
33

4-
Setting up a controller to act as a SOAP server is simple with a couple tools. You must, of course, have the
5-
`PHP SOAP`_ extension installed. As the PHP SOAP extension can not currently generate a WSDL, you must either
4+
Setting up a controller to act as a SOAP server is simple with a couple
5+
tools. You must, of course, have the `PHP SOAP`_ extension installed.
6+
As the PHP SOAP extension can not currently generate a WSDL, you must either
67
create one from scratch or use a 3rd party generator.
78

89
Here is an example o
@@ -24,10 +25,8 @@ Here is an example o
2425
2526
$server->handle();
2627
27-
$response->setContent(ob_get_contents());
28+
$response->setContent(ob_get_clean());
2829
29-
ob_clean();
30-
3130
return $response;
3231
}
3332
@@ -37,13 +36,18 @@ Here is an example o
3736
}
3837
}
3938
40-
Take note of the calls to ob_start, ob_get_contents, and ob_clean. These methods control `output buffering`_ which allows us to "trap" the echoed output of $server->handle().
41-
This is necessary because Symfony expects our controller to return a Response object with our output as it's "content".
42-
You must also remember to set the "Content-Type" header to "text/xml", as this is what the client will expect.
43-
So, we use ob_start to start buffering the STDOUT and use ob_get_contents to dump the echoed output into the content of our Response.
44-
Finally, we must call ob_clean to clear our output buffer and return our Response.
39+
Take note of the calls to ob_start, ob_get_contents, and ob_clean. These
40+
methods control `output buffering`_ which allows us to "trap" the echoed
41+
output of $server->handle().
42+
This is necessary because Symfony expects our controller to return a
43+
Response object with our output as it's "content". You must also remember
44+
to set the "Content-Type" header to "text/xml", as this is what the client
45+
will expect. So, we use ob_start to start buffering the STDOUT and use
46+
ob_get_clean to dump the echoed output into the content of our Response
47+
and clear our output buffer. Finally, we're ready to return our Response.
4548

46-
Below is an example calling our service using `NuSOAP`_ client. This example assumes indexAction in our controller above is accessible via the route "/soap".
49+
Below is an example calling our service using `NuSOAP`_ client. This example
50+
assumes indexAction in our controller above is accessible via the route "/soap".
4751

4852
.. code-block:: php
4953
$client = new soapclient('http://example.com/app.php/soap?wsdl', true);
@@ -54,7 +58,15 @@ An example WSDL is below.
5458

5559
.. code-block:: xml
5660
<?xml version="1.0" encoding="ISO-8859-1"?>
57-
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:arnleadservicewsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:arnleadservicewsdl">
61+
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
62+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
63+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
64+
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
65+
xmlns:tns="urn:arnleadservicewsdl"
66+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
67+
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
68+
xmlns="http://schemas.xmlsoap.org/wsdl/"
69+
targetNamespace="urn:arnleadservicewsdl">
5870
<types>
5971
<xsd:schema targetNamespace="urn:hellowsdl">
6072
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
@@ -78,8 +90,14 @@ An example WSDL is below.
7890
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
7991
<operation name="hello">
8092
<soap:operation soapAction="urn:arnleadservicewsdl#hello" style="rpc"/>
81-
<input><soap:body use="encoded" namespace="urn:hellowsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
82-
<output><soap:body use="encoded" namespace="urn:hellowsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
93+
<input>
94+
<soap:body use="encoded" namespace="urn:hellowsdl"
95+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
96+
</input>
97+
<output>
98+
<soap:body use="encoded" namespace="urn:hellowsdl"
99+
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
100+
</output>
83101
</operation>
84102
</binding>
85103
<service name="hellowsdl">
@@ -92,4 +110,4 @@ An example WSDL is below.
92110
93111
.. _`PHP SOAP`: http://php.net/manual/en/book.soap.php
94112
.. _`NuSOAP`: http://sourceforge.net/projects/nusoap
95-
.. _`output buffering`: http://php.net/manual/en/book.outcontrol.php
113+
.. _`output buffering`: http://php.net/manual/en/book.outcontrol.php

0 commit comments

Comments
 (0)