Calling a .NET asmx web service over https from PHP

  1. Enable SOAP by uncommenting “extension=php_soap.dll” in php.ini
  2. https should be included in “Registered PHP Streams” (phpinfo) – uncomment “extension=php_openssl.dll” in php.ini
// SOAP client

$wsdl = 'https://www.example.com/services/ProductManagement.asmx?wsdl';
$endpoint = array
(
	'location' => 'https://www.example.com/services/ProductManagement.asmx'
);
$soapClient = new SoapClient($wsdl, $endpoint);

// SOAP header

$soapHeaders = array();

$namespace = 'http://www.example.com/services/ProductManagement';
$elementName = 'Authentication';
$authenticationHeader = array
(
	'Username' => 'user9',
	'Password' => 'pass1234',
);
$soapHeader = new SoapHeader($namespace, $elementName, $authenticationHeader);
$soapHeaders[] = $soapHeader;

$soapClient->__setSoapHeaders($soapHeaders);

// SOAP call

$parameters->productCode = '9555170408350';

try
{
	$result = $soapClient->GetProduct($parameters);
}
catch (SoapFault $fault)
{
	echo "Fault code: {$fault->faultcode}<br />\n";
	echo "Fault string: {$fault->faultstring}<br />\n";
	if ($soapClient != null)
	{
		$soapClient = null;
	}
	exit();
}
$soapClient = null;

//echo "<pre>\n";
//print_r($result);
//echo "</pre>\n";

echo "Product code: {$result->GetProductResult->ProductCode}<br />\n";
echo "Name: {$result->GetProductResult->Name}<br />\n";
echo "Description: {$result->GetProductResult->Description}<br />\n";
echo "Category: {$result->GetProductResult->Category}<br />\n";
echo "SKU: {$result->GetProductResult->SKU}<br />\n";
echo "Manufacturer: {$result->GetProductResult->Manufacturer}<br />\n" ;
echo "Brand: {$result->GetProductResult->Brand}<br />\n";
echo "In stock: ";
echo ($result->GetProductResult->IsInStock ? "Yes" : "No") . "<br />\n";

26 March 2010 | PHP | Comments

Comments:

  1.  
  2.  
  3.