user1499458
user1499458

Reputation:

Making a SOAP request

I am new to PHP - Started little over a month back with PHP, JS and HTML with a few hours a day.

I have done a lot of homework on this but can't make head and tail out when it comes to implementation. I don't have a hardcore programmer who could sit with me on this, hence here. But I am sure if this question is answered, it would help a lot of newbir and experienced programmers there

The Problem - I can understand the concept of SOAP but cant makout how to make a simple soap request. What would be the steps in PHP.

//php SOAP extention is properly installed

Create a new SOAP client :

$variable = new SoapClient ;

$inputxml = " the input XML file as a string ";

varibale__doRequest($input xml, "string location -??

I have the XML input as a variable.. what location do i specify.. need to enable cache and a cache location ??,...) Thats the php function i am trying to use - how to use this http://www.php.net/manual/en/soapclient.dorequest.php

// PHP code to obtain response as XML // How to store the reponse in a variable as a string

Can someone demonstrate a simple SOAP request using PHP on a blog.

I couldnt find one example, all focus on creating SOAP services or SOAP servers.. I just wanna create a SOAP client and make a request in PHP - any detailed laymnas guide - PHP specific ??

This is the SOAP service I am struggling with - Find Company by Keyword at

http://developer.dnb.com/service-directory/sales/16682663-1.html

If someone could write a single post blog explaning the details, would be immensely grateful

PS: Not sure if my frustration is justified, but SOAP and REST concepts make programming sound like Rocket Science.. I have spent over a week, 8 hrs a day, dont have a clear idea on making SOAP requests though I have a fair understanding of the SOAP concept. As far as REST goes, it has me super confused - i don wanna touch that thing here at the moment.

Upvotes: 1

Views: 4651

Answers (2)

Vince Lowe
Vince Lowe

Reputation: 3620

There is the php soap client but you dont HAVE to use it.. you can build your request manually and post it with curl, you can then parse the response as you like.

/**
* Request login body
*/
const REQUEST_LOGIN = '<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.company.com/soap" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding">
 <env:Body>
  <ns1:RequestLogin xmlns:ns1="http://www.company.com/soap">
   <ns1:Name>%username%</ns1:Name>
   <ns1:OrgId>0</ns1:OrgId>
   <ns1:AuthType>simple</ns1:AuthType>
  </ns1:RequestLogin>
 </env:Body>
</env:Envelope>
';

Upvotes: 2

Matt Farina
Matt Farina

Reputation: 597

SOAP in PHP is a little easier than it seems. If you are looking for a long form tutorial there is a nice one up on DevZone. I would also keep the SoapClient class documentation handy.

The gist of working with Soap

// $endpoint is the callback/uri of the WSDL.
// $options is an array of options.
$client = new SoapClient($endpoint, $options);

You can learn more about he options and endpoint in the details for the constructor.

PHP has some magic methods and __call is one of them. The easiest way to use SOAP is often to just call an available method. For example:

$response = $client->getLoginToken(array(
    'siteid' => 'foo',
    'secid' => 'bar',
));

In this case getLoginToken is a SOAP method call. The SOAP client sees that it's not a method on the object and passes that as the method on to SOAP. The array passed in is arguments to pass on to the SOAP endpoint as arguments.

I would also checkout the examples on the soapCall page. Best of luck.

Upvotes: 0

Related Questions