Click here to Skip to main content
13,041,923 members (81,388 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 21 Sep 2010

Another way of Consuming WCF from PHP, iPhone, JavaMobile, JSON clients

, 27 Sep 2010
Rate this:
Please Sign up or sign in to vote.
There is a simple way to consume WCF from clients which do not support Microsoft's SOAP implementation. It is achieved by using REST to accept data and convert REST calls to SOAP calls with the PHP Framework.
Let me introduce the tool I use to connect to WCF web services from ANY mobile clients. You can access WCF from iPhone, Java ME devices, Android, PHP front-ends and whatever you like.[^]

Mobile clients do not support what Microsoft did to implement SOAP in WCF. iPhone even does not support SOAP well at all. Java Mobile supports Sun's SOAP but does not like Microsoft's SOAP.

But there is an easy solution to this:

1. We implement a SOAP client in PHP which is easy to use from PHP code;
2. We implement a REST interface to this SOAP client to make it accessible from any client supporting HTTP;
3. We implement additional business logic if appropriate;
4. We use PHP through REST interface and it translates everything to our SOAP server.

The following code calls the SOAP web service from PHP (again part of Emission Framework):

 * PHP Framework Integration SOAP Web Service Reference class
 * @author Andrew <>
 * @author Frozen Rain <>
class SOAPWebServiceReference extends WebServiceReference {
    private $_proxyHost = null;
    private $_proxyPort = null;
    public function __construct($uri) {
    public function execute($method, $arguments) {
        $this->_proxyHost = Configuration::get("Framework.Integration.SOAPWebService.SOAPWebServiceReference._proxyHost");
        $this->_proxyPort = Configuration::get("Framework.Integration.SOAPWebService.SOAPWebServiceReference._proxyPort");
        $settings = array();
        if (isset($this->_proxyHost)) {
            $settings['proxy_host'] = $this->_proxyHost;
        if (isset($this->_proxyPort)) {
            $settings['proxy_port'] = $this->_proxyPort;
        $soapClient = new SoapClient($this->_uri, $settings);
        $timeStart = microtime(TRUE);
        $response = $soapClient->$method($arguments);
        $timeInterval = microtime(TRUE) - $timeStart;
        Trace::writeLine("SOAPWebServiceReference::execute($method, ...) took $timeInterval");
        $method .= "Result";
        return SOAPSerializer::fromResult($response->$method);

There is an additional task to understand what SoapClient (built-in PHP class) returns to us. Therefore we have an additional logic which parses it (see our site).

Very easy! And it is even easier with Vitche Emission PHP Framework. Because it already has all code bundled.[^]

The following lines of code do the whole job of converting REST to SOAP:

 * PHP Framework Integration HTTP-to-SOAP Gateway Web Service class
 * This service makes SOAP services available to callers through the usual
 * HTTP REST interface
 * Description of HTTPSOAPGatewayWebService
 * @author Andrew <>
 * @author Frozen Rain <>
class HTTPSOAPGatewayWebService extends HTTPWebService {
    function __construct() {
    function onMethodCall($strClassName, $strMethodName, $arRequest) {
        // Parse request
        $url = null;
        $arguments = array();
        foreach ($arRequest as $key => $value) {
            if ('url' == $key) {
                $url = $value;
            } else {
                $arguments[$key] = $value;
        $reference = new SOAPWebServiceReference($url);
        return JSONSerializer::toString($reference->execute($strMethodName, $arguments));

And now a bit more about accessing JSON services from iPhone. I had no wish to write anything in my own.

But I liked the following very much and now use it:[^]

Also note that it has some parsing errors because it does not support "undefined" in JSON. And we are using "undefined" to serialize "null" values in Vitche PHP Framework.

Write me and I will send a fixed version of JSON framework. Or find that yourself.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Frozen Rain
Web Developer
Ukraine Ukraine
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

GeneralPS: I was inserting a link to Pin
Frozen Rain27-Sep-10 3:11
memberFrozen Rain27-Sep-10 3:11 
GeneralHi, All! My excuises for links. It had to be *.html but som... Pin
Frozen Rain27-Sep-10 3:01
memberFrozen Rain27-Sep-10 3:01 
GeneralYour links above do not work. Pin
Steve Maier22-Sep-10 12:06
memberSteve Maier22-Sep-10 12:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 27 Sep 2010
Article Copyright 2010 by Frozen Rain
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid