1

Not really a PHP developer, but I have PHP hosting and would like to create a PHP Web Service on it to be consumed by a .NET Client, I am thinking of using WSDL with NUSoap.

OR

A more modern solution, which I am not sure would be easier, would be to use OData. Which one would be easier?

Cesar
  • 3,519
  • 2
  • 29
  • 43
emalamisura
  • 2,816
  • 2
  • 29
  • 34

3 Answers3

4

The easiest for you c# developers is to develop a soap service with a WSDL. It will be a pain to create the service in php.

A better alternative is to create a REST webservice that communicates using JSON. It will take a bit more code on the client side, but it will be easier to consume on other platforms, and will be snap to develop in php.

Here is an example of a very simple REST-JSON web server in php.

function finder($person)
{
     $data = array();

     $data['sue']['full_name'] = 'Sue Thompson';
     $data['sue']['location']['city'] = 'San Francisco';
     $data['sue']['location']['state'] = 'California';

     $data['jack']['full_name'] = 'Jack Black';
     $data['jack']['location']['city'] = 'San Anselmo';
     $data['jack']['location']['state'] = 'California'; 

    if (!isset($data[$person))
    {
        return $data[$person];
    }
    else
    {
        // make sure you document this
        return array('error' => "An error has occured");
    }
}

// you can take parameters as url query strings or as json.
// if your input is simple, query strings are easier. 
$person = $_GET['person'];

echo json_encode(finder($person));
Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
  • Didn't the question specify PHP ? – Wadih M. Jan 11 '11 at 19:44
  • She said PHP server, .net client. the REST web service will be easier to develop the server side code, is well known (it is how Google's web services work). It just doesn't work as automatically on the .net side. – Byron Whitlock Jan 11 '11 at 19:46
  • Right its the server side is PHP which I am less familiar with so less complex is better, the client side is .NET, JSON is actually a good idea... – emalamisura Jan 11 '11 at 19:53
2

Please for the love of God do not use SOAP. It is awful and terrible.

Use REST (or at least GET and POST) and JSON. So much easier.

see SOAP or REST for Web Services?

UPDATE: I originally ranted against XML, but it has its place. JSON is better though (less verbose).

Community
  • 1
  • 1
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • XML has it's place. It depends on your audience. XML isn't that bad once you learn your way around a parser. SOAP is almost always fail, but if your clients are .NET, SOAP is pretty nice for them. – Byron Whitlock Jan 11 '11 at 20:11
0

It is well explained on this site: http://wso2.org/library/3393

Aldee
  • 4,439
  • 10
  • 48
  • 71