Archives for the 'PHP' Category

Calling a SOAP web service from PHP

The SOAP binding is RPC/encoded, and the WSDL is not published.
Using the PHP SoapClient:

define(’NEWLINE’, “<br />\n”);

// SOAP client

$options = array
(
‘location’ => ‘https://example.com:1234/sample/service’,
‘uri’ => ‘http://example.com/sample/namespace/data’,
’style’ => SOAP_RPC,
‘use’ => SOAP_ENCODED,
‘trace’ => true // in conjunction with $soapClient->__getLastRequest() below
);
$soapClient = new SoapClient(null, $options);

// SOAP header

$nsHeader = ‘http://example.com/sample/namespace/security’;
$elementName = ‘Security’;

$usernameToken->Username = new SoapVar(’user9′, XSD_STRING, null, null, null, $nsHeader);
$usernameToken->Password = […]

14 April 2010 | PHP | No Comments

Calling a WCF service from PHP

The WCF service needs to use basicHttpBinding.
The PHP code:

define(’NEWLINE’, “<br />\n”);

// SOAP client

$wsdl = ‘http://example.com/SampleWcfService.SampleService.Service?wsdl’;
$soapClient = new SoapClient($wsdl, array(’cache_wsdl’ => 0));

// SOAP call

$sampleData->SampleProperty = “abc”;

$parameters->sampleId = 123;
$parameters->sampleData = $sampleData;

try
{
$result = $soapClient->GetData($parameters);
}
catch (SoapFault $fault)
{
echo “Fault code: {$fault->faultcode}” . NEWLINE;
echo “Fault string: {$fault->faultstring}” . NEWLINE;
if ($soapClient != null)
{
$soapClient = null;
}
exit();
}
$soapClient = null;

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

echo “Return value: {$result->GetDataResult}” […]

8 April 2010 | .NET, PHP | 1 Comment

Using log4php

A how-to for the excellent log4php:

Rolling daily file
Log error statements into one file, and info statements into another
Send emails

Usage

include_once(’/var/www/example/components/log4php/2.0.0/Logger.php’);

class Example
{
private $logger;

function __construct()
{
$loggerConfig = ‘/var/www/example/config/log4php.xml’;
Logger::configure($loggerConfig);
$this->logger = Logger::getLogger(’example’);
}

public function doSomething()
{
$var = $this->getSomeValue();
$this->logger->debug(’in doSomething: $var = ‘ . $var);
try
{
$this->doSomethingSpecific();
}
catch (Exception $ex)
{
$this->logger->error($ex->getMessage());
throw new Exception(”There is a problem with Something. We apologize for any inconvenience caused.”);
}
$this->logger->info(”doSomething successful”);
}
}

log4php.xml

<log4php:configuration xmlns:log4php=”http://logging.apache.org/log4php/”>
[…]

27 March 2010 | PHP | No Comments

Calling a .NET asmx web service over https from PHP

Enable SOAP by uncommenting “extension=php_soap.dll” in php.ini
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 […]

26 March 2010 | PHP | No Comments

Separate Instances of MySQL 4.0 and MySQL 4.1 on Windows

Assuming you already have MySQL 4.0 running on its default port (3306), install MySQL 4.1 and set its service name to MySQL41 and its port to 3307.
The ASP connection string is as follows:
“driver={MYSQL ODBC 3.51 Driver};” & _
“server=localhost;port=3307;” & _
“uid=user1;pwd=a_password;database=db1″
The PHP connection method is as follows:
$c = mysql_connect(”localhost:3307″, “user1″, “a_password”);
mysql_select_db(”db1″, $c);

28 March 2007 | MySQL, ASP, PHP | 1 Comment

idea rumah