1

There is a webservice (WSDL) with a lot of functions. I want to call one of these functions with PHP. The webservice provides a documentation wherein they put a format including header and xml, but I have no idea how I need to send the request from PHP. I searched for a couple of hours now, and I simply don't know.

An example request they provided:

POST POSTURL HTTP/1.1
Host: HOST
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "SOAPLOCATION"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Version xmlns="URL" />
  </soap:Body>
</soap:Envelope>

The response I should receive is also given, but I can't even send the request.

How do I send a request with PHP to get the response? I tried some PHP SoapClient things, but I can't find a easy to read tutorial or some clear explanation...

If anyone can help me, that would be great!

RobinV91nl
  • 53
  • 6
  • have you looked here: http://php.net/manual/en/class.soapclient.php – Tomer Aug 07 '12 at 13:56
  • Yes I looked at that, and I have no idea... I can create the SoapClient, then client->__getfunctions(), but I don't know how to call one of these functions? – RobinV91nl Aug 08 '12 at 07:54

2 Answers2

0

Mapping some typical information may look something like this.

        $data = array(
        'UserName'  => $user->getUsername(),
        'Password'  => $user->getPassword(),
        'Email'     => $user->getEmail(),
        'FirstName' => $user->getFirstName(),
        'LastName'  => $user->getLastName(),
    );


    $response = $this->getDatasource()->TheServiceMethodForCreatingAUser(
        array(
             'user' => $data
        )
    );

The response is then handled however you wish (via an entity or response object of some description). The header must be done seperately by using new SoapHeader().

Hope this helps.

MaxSan
  • 318
  • 1
  • 13
0

I've an addition to the question:

The request is as following:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns="...">
   <s:Body>
      <Search>
         <login>
            <Wholesaler>...</Wholesaler>
            <Username>...</Username>
            <Password>...</Password>
         </login>
         <itemRequests>
            <ItemRequest>
               <ArticleId>int</ArticleId>
               <SupplierId>int</SupplierId>
               <QuantityRequested>int</QuantityRequested>
            </ItemRequest>
         </itemRequests>
      </Search>
   </s:Body>
</s:Envelope>

There are two SoapHeaders I need to send:

Content-Type: text/xml; charset=utf-8
SOAPAction: URI

I do know the service provider and the action identifier.

If I have the following variables

$service
$action
$request
$header

How can I send the request in PHP? I tried

$client  = new SoapClient($service);
$result = $client->__doRequest($request, $service, $action);

But I do not receive a response it seems...

This is what the response should like:

Date: Thu, 09 Aug 2012 08:01:40 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 408
Cache-Control: private
Content-Type: text/xml; charset=utf-8


<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SearchResponse xmlns="...">
      <SearchResult>
        <Wholesaler>...</Wholesaler>
        <Username>...</Username>
        <Error>false</Error>
        <DateTime>2012-08-09T10:01:40.39125+02:00</DateTime>
        <ItemResults />
      </SearchResult>
    </SearchResponse>
  </s:Body>
</s:Envelope>

When I do a simple echo $result, the screen stays white and in the code there is no XML visible.

RobinV91nl
  • 53
  • 6