Jump to content

Using PHP to call SOAP Web Service


Travist6983

Recommended Posts

I will warn you that i have never used PHP to call a web service but have spent the last 2 days googling with trial and error and think that i have come to a point where i have no idea what to do as nothing is working.

Here is my PHP code...

<?php
$soapclient = new SoapClient('Link-To-EndPoint');
$params = array('Username' => 'Username', 
'Password' => 'Password', 
'clientRequestId' => 1, 
'projectNumber' => 64111, 
'requestDateTime' => '2014-03-16T11:05:24.572Z',
'itemNumber' => 'F00573019120B',
'projectNumber' => 64111
);
$response = $soapclient->GetItemDetailInfo($params);
echo '<pre>';
var_dump($response);
echo '</pre>';
?>

And here is the request, probably worth noting that this gives the full response and works when i use SOAP UI to make the request.

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Header>
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>Username</Username>
<Password>Password</Password>
</UsernameToken>
</Security>
</env:Header>
<env:Body>
<getItemDetailInfoRequest>
<requestHeader>
<clientRequestId>1</clientRequestId>
<projectNumber>64111</projectNumber>
<requestDateTime>2014-03-20T14:05:24.572Z</requestDateTime>
</requestHeader>
<getItemDetailInfoList>
<itemDetailSearchCriteria>
<itemNumber>F00573019120B</itemNumber>
<projectNumber>64111</projectNumber>
</itemDetailSearchCriteria>
</getItemDetailInfoList>
</getItemDetailInfoRequest>
</env:Body>
</env:Envelope>

When i load the page i get a blank screen nothing comes out from $response, I have no idea if i am close to making this work or if i am super far off with this. Using the above code i am able to make a public weather SOAP Web Service work which makes me think i am close.

Any help would be appreciated!

Link to comment
Share on other sites

I am completely new to SOAP calls in php. But I did give it a try based on help from google.

<?php
$client = new SoapClient("http://www.webservicex.net/globalweather.asmx?WSDL",array('proxy_host'     => "myproxy", 'proxy_port'     => 8080));
$params = array("CountryName" => "united states");
$response = $client->__soapCall("GetCitiesByCountry",array($params));

var_dump($response);
?>

and it did generate the needed output. 

although when I changed 

$response = $client->__soapCall("GetCitiesByCountry",array($params));

to

$response = $client->GetCitiesByCountry(array($params));

It didnt work, and threw and error.This might help.

 

(proxy setting not necessary).

Link to comment
Share on other sites

Thanks for the reply yeah i have a working weather one as well that is where my starting code came from 

<?php 
$soapclient = new SoapClient('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL');
$params = array('ZIP' => '48067');
$response = $soapclient->GetCityForecastByZIP($params);
echo '<pre>';
var_dump($response);
echo '</pre>';
?>

I think there were some issues in my array as well so i have now updated to be this. 

<?php 
// Create the client object
$soapclient = new SoapClient('Link-To-WSDL-End-Point');
$Header = array(
    'UsernameToken' => array(
            'Username' => 'Username', 
            'Password' => 'Password'
        )
);  
$Body = array(
    'getItemDetailInfoRequest' => array(
        'requestHeader' => array(
            'clientRequestId' => 1,
            'projectNumber' => 64111,
            'requestDateTime' => '2014-03-20T14:05:24.572Z'
        ),
        'getItemDetailInfoList' => array(
            'itemDetailSearchCriteria' => array(
                'itemNumber' => 'F00573019120B',
                'projectNumber' => 64111
            )
        )
    )
);  

$response = $client->__soapCall("UsernameToken",array($Header), "getItemDetailInfoRequest",array($Body)); 
// $response = $soapclient->UsernameToken($Header)->getItemDetailInfoRequest($Body); 
echo '<pre>'; 
var_dump($response); 
echo '</pre>'; 

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.